Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
Added backup feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Jizzu committed Mar 30, 2018
1 parent f00e405 commit 1e59ace
Show file tree
Hide file tree
Showing 24 changed files with 572 additions and 90 deletions.
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "apps.jizzu.simpletodo"
minSdkVersion 19
targetSdkVersion 27
versionCode 4
versionName "1.0"
versionCode 5
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package="apps.jizzu.simpletodo">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
*/
public class AddTaskActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {

EditText mTitle;
TextInputLayout mTaskTitleLayout;
RelativeLayout mReminderLayout;
Calendar mCalendar;
EditText mDate;
EditText mTime;
SwitchCompat mReminderSwitch;
private EditText mTitle;
private TextInputLayout mTaskTitleLayout;
private RelativeLayout mReminderLayout;
private Calendar mCalendar;
private EditText mDate;
private EditText mTime;
private SwitchCompat mReminderSwitch;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -196,6 +196,14 @@ public void onClick(View view) {
});
}

/**
* Method for hiding the soft keyboard.
*/
private void hideKeyboard(EditText editText) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}

/**
* Hides the soft keyboard when the user clicks on the home button.
*/
Expand All @@ -205,14 +213,6 @@ protected void onStop() {
hideKeyboard(mTitle);
}

/**
* Method for hiding the soft keyboard.
*/
public void hideKeyboard(EditText editText) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}

/**
* The handler for clicking the close button in the toolbar.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand Down Expand Up @@ -46,18 +47,19 @@
*/
public class EditTaskActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {

EditText mTitle;
TextInputLayout mTaskTitleLayout;
RelativeLayout mReminderLayout;
Calendar mCalendar;
EditText mDateEditText;
EditText mTimeEditText;
SwitchCompat mReminderSwitch;
RecyclerViewAdapter mAdapter;
long mId;
long mDate;
int mPosition;
long mTimeStamp;
private Context mContext;
private EditText mTitle;
private TextInputLayout mTaskTitleLayout;
private RelativeLayout mReminderLayout;
private Calendar mCalendar;
private EditText mDateEditText;
private EditText mTimeEditText;
private SwitchCompat mReminderSwitch;
private RecyclerViewAdapter mAdapter;
private long mId;
private long mDate;
private int mPosition;
private long mTimeStamp;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -87,6 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
TextView reminderText = findViewById(R.id.tvSetReminder);

MainActivity.mActivityIsShown = true;
mContext = getApplicationContext();

// Get the resolution of the user's screen
Display d = ((WindowManager) this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Expand Down Expand Up @@ -228,7 +231,7 @@ public void onClick(View view) {
} else if (mTitle.getText().toString().trim().length() == 0) {
mTitle.setError(getString(R.string.error_spaces));
} else {
DBHelper dbHelper = DBHelper.getInstance(MainActivity.mContext);
DBHelper dbHelper = DBHelper.getInstance(mContext);

ModelTask task = new ModelTask(mId, mTitle.getText().toString(), mDate, mPosition, mTimeStamp);

Expand All @@ -246,7 +249,7 @@ public void onClick(View view) {

if (task.getDate() != 0 && task.getDate() <= Calendar.getInstance().getTimeInMillis()) {
task.setDate(0);
Toast.makeText(MainActivity.mContext, getString(R.string.toast_incorrect_time), Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, getString(R.string.toast_incorrect_time), Toast.LENGTH_SHORT).show();
} else if (task.getDate() != 0) {
AlarmHelper alarmHelper = AlarmHelper.getInstance();
alarmHelper.setAlarm(task);
Expand Down Expand Up @@ -297,7 +300,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;

case R.id.action_delete:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
AlertDialog.Builder alertDialog;
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
alertDialog = new AlertDialog.Builder(this);
} else {
alertDialog = new AlertDialog.Builder(this, R.style.DialogTheme);
}
alertDialog.setTitle(R.string.dialog_title);
alertDialog.setMessage(R.string.dialog_message);
alertDialog.setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
Expand Down
39 changes: 24 additions & 15 deletions app/src/main/java/apps/jizzu/simpletodo/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@
import static android.content.ContentValues.TAG;


public class MainActivity extends AppCompatActivity implements RecyclerViewAdapter.UpdateNotificationDataCallback {
public class MainActivity extends AppCompatActivity implements RecyclerViewAdapter.AdapterCallback {

private Context mContext;
private RecyclerViewEmptySupport mRecyclerView;
public RecyclerViewAdapter mAdapter;
private RecyclerViewAdapter mAdapter;
private RelativeLayout mEmptyView;
private DBHelper mHelper;
public static FloatingActionButton mFab;
private PreferenceHelper mPreferenceHelper;
private RecyclerView.LayoutManager mLayoutManager;
public static boolean mSearchViewIsOpen;
private MaterialSearchView mSearchView;
private NotificationManager mNotificationManager;
private FloatingActionButton mFab;

public static boolean mSearchViewIsOpen;
public static boolean mShowAnimation;
public static boolean mActivityIsShown;

// TODO: Find better way to get the MainActivity context.
public static Context mContext;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Set up "What's New" screen
WhatsNew whatsNew = WhatsNew.newInstance(
new WhatsNewItem(getString(R.string.whats_new_item_1_title), getString(R.string.whats_new_item_1_text))
new WhatsNewItem(getString(R.string.whats_new_item_1_title), getString(R.string.whats_new_item_1_text)),
new WhatsNewItem(getString(R.string.whats_new_item_2_title), getString(R.string.whats_new_item_2_text)),
new WhatsNewItem(getString(R.string.whats_new_item_3_title), getString(R.string.whats_new_item_3_text))
);
whatsNew.setTitleColor(ContextCompat.getColor(this, R.color.colorAccent));
whatsNew.setTitleText(getString(R.string.whats_new_title));
Expand All @@ -92,6 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {
whatsNew.presentAutomatically(MainActivity.this);

mContext = MainActivity.this;
mSearchViewIsOpen = false;
setTitle("");

// Initialize ALARM_SERVICE
Expand All @@ -108,6 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {

mEmptyView = findViewById(R.id.empty);

mRecyclerView = new RecyclerViewEmptySupport(mContext);
mRecyclerView = findViewById(R.id.tasksList);
mRecyclerView.setHasFixedSize(true);

Expand Down Expand Up @@ -230,7 +232,7 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
/**
* Finds tasks by the title in the database.
*/
public void findTasks(String title) {
private void findTasks(String title) {
mSearchViewIsOpen = true;
Log.d(TAG, "findTasks: SearchView Title = " + title);
mAdapter.removeAllItems();
Expand All @@ -250,7 +252,7 @@ public void findTasks(String title) {
/**
* Reads all tasks from the database and adds them to the RecyclerView list.
*/
public void addTasksFromDB() {
private void addTasksFromDB() {
mAdapter.removeAllItems();
List<ModelTask> taskList = mHelper.getAllTasks();

Expand All @@ -272,7 +274,7 @@ private void startEmptyViewAnimation() {
/**
* Updates widget data.
*/
public void updateWidget() {
private void updateWidget() {
Log.d(TAG, "WIDGET IS UPDATED!");
Intent intent = new Intent(this, WidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
Expand All @@ -285,7 +287,7 @@ public void updateWidget() {
/**
* Updates general notification data.
*/
public void updateGeneralNotification() {
private void updateGeneralNotification() {
if (mPreferenceHelper.getBoolean(PreferenceHelper.GENERAL_NOTIFICATION_IS_ON)) {
if (mAdapter.getItemCount() != 0) {
showGeneralNotification();
Expand All @@ -300,7 +302,7 @@ public void updateGeneralNotification() {
/**
* Set up and show general notification.
*/
public void showGeneralNotification() {
private void showGeneralNotification() {
StringBuilder stringBuilder = new StringBuilder();

Intent resultIntent = new Intent(this, MainActivity.class);
Expand Down Expand Up @@ -365,7 +367,7 @@ public void showGeneralNotification() {
/**
* Removes general notification.
*/
public void removeGeneralNotification() {
private void removeGeneralNotification() {
if (mNotificationManager != null) {
mNotificationManager.cancel(1);
}
Expand All @@ -379,6 +381,11 @@ public void updateData() {
updateGeneralNotification();
}

@Override
public void showFAB() {
mFab.show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
Expand Down Expand Up @@ -428,6 +435,8 @@ protected void onStop() {
@Override
protected void onResume() {
super.onResume();

//addTasksFromDB();
mFab.setVisibility(View.GONE);

if (mPreferenceHelper.getBoolean(PreferenceHelper.ANIMATION_IS_ON)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ListItemTouchHelper extends ItemTouchHelper.Callback {
/**
* Constructor for mAdapter initialization.
*/
public ListItemTouchHelper(RecyclerViewAdapter adapter, RecyclerView recyclerView) {
protected ListItemTouchHelper(RecyclerViewAdapter adapter, RecyclerView recyclerView) {
mAdapter = adapter;
mRecyclerView = recyclerView;
}
Expand Down
Loading

0 comments on commit 1e59ace

Please sign in to comment.