-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0e98fe5
Showing
27 changed files
with
977 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# files for the dex VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# generated files | ||
bin/ | ||
gen/ | ||
gen-external-apklibs/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# intellij & maven | ||
.classpath | ||
.project | ||
.settings/ | ||
.idea/ | ||
*.iml | ||
*.iws | ||
.DS_Store | ||
log/ | ||
target/ | ||
tmp/ | ||
out/ | ||
|
||
# Gradle | ||
.gradle | ||
build/** | ||
libraries/build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 22 | ||
buildToolsVersion "22.0.1" | ||
|
||
defaultConfig { | ||
applicationId "lgvalle.com.fluxtodo" | ||
minSdkVersion 16 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:22.2.0' | ||
compile 'com.squareup:otto:1.3.8' | ||
compile 'com.android.support:recyclerview-v7:22.2.0' | ||
compile 'com.android.support:design:22.2.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/lgvalle/Developer/android-sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/lgvalle/com/fluxtodo/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package lgvalle.com.fluxtodo; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="lgvalle.com.fluxtodo" > | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name=".TodoActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
146 changes: 146 additions & 0 deletions
146
app/src/main/java/lgvalle/com/fluxtodo/TodoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package lgvalle.com.fluxtodo; | ||
|
||
import android.os.Bundle; | ||
import android.support.design.widget.Snackbar; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.text.TextUtils; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.CheckBox; | ||
import android.widget.EditText; | ||
|
||
import com.squareup.otto.Bus; | ||
import com.squareup.otto.Subscribe; | ||
|
||
import lgvalle.com.fluxtodo.actions.ActionsCreator; | ||
import lgvalle.com.fluxtodo.dispatcher.Dispatcher; | ||
import lgvalle.com.fluxtodo.stores.TodoStore; | ||
|
||
public class TodoActivity extends AppCompatActivity { | ||
|
||
private EditText mainInput; | ||
private ViewGroup mainLayout; | ||
private Dispatcher dispatcher; | ||
private ActionsCreator actionsCreator; | ||
private TodoStore todoStore; | ||
private TodoRecyclerAdapter listAdapter; | ||
private CheckBox mainCheck; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
initDependencies(); | ||
setupView(); | ||
} | ||
|
||
private void initDependencies() { | ||
dispatcher = Dispatcher.get(new Bus()); | ||
actionsCreator = ActionsCreator.get(dispatcher); | ||
todoStore = TodoStore.get(dispatcher); | ||
} | ||
|
||
private void setupView() { | ||
mainLayout = ((ViewGroup) findViewById(R.id.main_layout)); | ||
mainInput = (EditText) findViewById(R.id.main_input); | ||
|
||
Button mainAdd = (Button) findViewById(R.id.main_add); | ||
mainAdd.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
addTodo(); | ||
resetMainInput(); | ||
} | ||
}); | ||
mainCheck = (CheckBox) findViewById(R.id.main_checkbox); | ||
mainCheck.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
checkAll(); | ||
} | ||
}); | ||
Button mainClearCompleted = (Button) findViewById(R.id.main_clear_completed); | ||
mainClearCompleted.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
clearCompleted(); | ||
resetMainCheck(); | ||
} | ||
}); | ||
|
||
|
||
RecyclerView mainList = (RecyclerView) findViewById(R.id.main_list); | ||
mainList.setLayoutManager(new LinearLayoutManager(this)); | ||
listAdapter = new TodoRecyclerAdapter(actionsCreator); | ||
mainList.setAdapter(listAdapter); | ||
} | ||
|
||
private void updateUI() { | ||
listAdapter.setItems(todoStore.getTodos()); | ||
|
||
if (todoStore.canUndo()) { | ||
Snackbar snackbar = Snackbar.make(mainLayout, "Element deleted", Snackbar.LENGTH_LONG); | ||
snackbar.setAction("Undo", new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
actionsCreator.undoDestroy(); | ||
} | ||
}); | ||
snackbar.show(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
dispatcher.register(this); | ||
dispatcher.register(todoStore); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
dispatcher.unregister(this); | ||
dispatcher.unregister(todoStore); | ||
} | ||
|
||
private void addTodo() { | ||
if (validateInput()) { | ||
actionsCreator.create(getInputText()); | ||
} | ||
} | ||
|
||
private void checkAll() { | ||
actionsCreator.toggleCompleteAll(); | ||
} | ||
|
||
private void clearCompleted() { | ||
actionsCreator.destroyCompleted(); | ||
} | ||
|
||
private void resetMainInput() { | ||
mainInput.setText(""); | ||
} | ||
|
||
private void resetMainCheck() { | ||
if (mainCheck.isChecked()) { | ||
mainCheck.setChecked(false); | ||
} | ||
} | ||
|
||
private boolean validateInput() { | ||
return !TextUtils.isEmpty(getInputText()); | ||
} | ||
|
||
private String getInputText() { | ||
return mainInput.getText().toString(); | ||
} | ||
|
||
@Subscribe | ||
public void onTodoStoreChange(TodoStore.TodoStoreChangeEvent event) { | ||
updateUI(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
app/src/main/java/lgvalle/com/fluxtodo/TodoRecyclerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package lgvalle.com.fluxtodo; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.text.SpannableString; | ||
import android.text.style.StrikethroughSpan; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.CheckBox; | ||
import android.widget.TextView; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import lgvalle.com.fluxtodo.actions.ActionsCreator; | ||
import lgvalle.com.fluxtodo.model.Todo; | ||
|
||
/** | ||
* Created by lgvalle on 28/07/15. | ||
*/ | ||
public class TodoRecyclerAdapter extends RecyclerView.Adapter<TodoRecyclerAdapter.ViewHolder> { | ||
|
||
private static ActionsCreator actionsCreator; | ||
private List<Todo> todos; | ||
|
||
public TodoRecyclerAdapter(ActionsCreator actionsCreator) { | ||
this.todos = new ArrayList<>(); | ||
TodoRecyclerAdapter.actionsCreator = actionsCreator; | ||
} | ||
|
||
@Override | ||
public ViewHolder onCreateViewHolder(ViewGroup parent, int i) { | ||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.todo_row_layout, parent, false); | ||
return new ViewHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(ViewHolder viewHolder, int i) { | ||
viewHolder.bindView(todos.get(i)); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return todos.size(); | ||
} | ||
|
||
public void setItems(List<Todo> todos) { | ||
this.todos = todos; | ||
notifyDataSetChanged(); | ||
} | ||
|
||
public static class ViewHolder extends RecyclerView.ViewHolder { | ||
public TextView todoText; | ||
public CheckBox todoCheck; | ||
public Button todoDelete; | ||
|
||
public ViewHolder(View v) { | ||
super(v); | ||
todoText = (TextView) v.findViewById(R.id.row_text); | ||
todoCheck = (CheckBox) v.findViewById(R.id.row_checkbox); | ||
todoDelete = (Button) v.findViewById(R.id.row_delete); | ||
|
||
} | ||
|
||
public void bindView(final Todo todo) { | ||
if (todo.isComplete()) { | ||
SpannableString spanString = new SpannableString(todo.getText()); | ||
spanString.setSpan(new StrikethroughSpan(), 0, spanString.length(), 0); | ||
todoText.setText(spanString); | ||
} else { | ||
todoText.setText(todo.getText()); | ||
} | ||
|
||
|
||
todoCheck.setChecked(todo.isComplete()); | ||
todoCheck.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
actionsCreator.toggleComplete(todo); | ||
} | ||
}); | ||
|
||
todoDelete.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
actionsCreator.destroy(todo.getId()); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.