diff --git a/app/build/outputs/apk/debug/app-debug.apk b/app/build/outputs/apk/debug/app-debug.apk index 0c16816..428df9a 100644 Binary files a/app/build/outputs/apk/debug/app-debug.apk and b/app/build/outputs/apk/debug/app-debug.apk differ diff --git a/app/src/androidTest/java/com/thecoolguy/rumaan/fileio/FileEntityDaoTest.java b/app/src/androidTest/java/com/thecoolguy/rumaan/fileio/FileEntityDaoTest.java index 6187340..49b4894 100644 --- a/app/src/androidTest/java/com/thecoolguy/rumaan/fileio/FileEntityDaoTest.java +++ b/app/src/androidTest/java/com/thecoolguy/rumaan/fileio/FileEntityDaoTest.java @@ -3,7 +3,6 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; -import android.arch.lifecycle.LiveData; import android.arch.persistence.room.Room; import android.support.test.InstrumentationRegistry; import android.support.test.filters.LargeTest; @@ -108,7 +107,7 @@ public void accept(FileEntity fileEntity) { assertEquals(items, database.uploadItemDao().numberOfItems()); - List list = database.uploadItemDao().allUploads(); + List list = database.uploadItemDao().getAllUploads().getValue(); assertNotNull(list); assertEquals(fileEntities, list); } diff --git a/app/src/main/java/com/thecoolguy/rumaan/fileio/data/db/UploadItemDao.java b/app/src/main/java/com/thecoolguy/rumaan/fileio/data/db/UploadItemDao.java index 2bf83fb..6bdf650 100644 --- a/app/src/main/java/com/thecoolguy/rumaan/fileio/data/db/UploadItemDao.java +++ b/app/src/main/java/com/thecoolguy/rumaan/fileio/data/db/UploadItemDao.java @@ -23,7 +23,7 @@ public interface UploadItemDao { void delete(FileEntity... fileEntity); @Query("DELETE FROM " + TABLE_NAME) - void deleteAll(); + void clearAll(); @Query("SELECT DISTINCT count(*) FROM " + TABLE_NAME) int numberOfItems(); @@ -31,6 +31,4 @@ public interface UploadItemDao { @Query("SELECT * FROM " + TABLE_NAME) LiveData> getAllUploads(); - @Query("SELECT * FROM " + TABLE_NAME) - List allUploads(); } diff --git a/app/src/main/java/com/thecoolguy/rumaan/fileio/repository/ClearHistoryWorker.kt b/app/src/main/java/com/thecoolguy/rumaan/fileio/repository/ClearHistoryWorker.kt new file mode 100644 index 0000000..bce1df1 --- /dev/null +++ b/app/src/main/java/com/thecoolguy/rumaan/fileio/repository/ClearHistoryWorker.kt @@ -0,0 +1,15 @@ +package com.thecoolguy.rumaan.fileio.repository + +import androidx.work.Worker +import com.thecoolguy.rumaan.fileio.data.db.UploadHistoryRoomDatabase + +class ClearHistoryWorker : Worker() { + + override fun doWork(): WorkerResult { + UploadHistoryRoomDatabase.getInstance(applicationContext) + .uploadItemDao() + .clearAll() + + return WorkerResult.SUCCESS + } +} \ No newline at end of file diff --git a/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/MainActivity.java b/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/MainActivity.java index 8060c56..aa80d05 100644 --- a/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/MainActivity.java +++ b/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/MainActivity.java @@ -113,14 +113,18 @@ protected void onCreate(Bundle savedInstanceState) { setSupportActionBar(toolbar); // set up initial fragment + setUpInitialFragment(); + + viewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class); + } + + private void setUpInitialFragment() { getSupportFragmentManager() .beginTransaction() .add(R.id.parent_fragment_container, ChooseFileFragment.newInstance(), ChooseFileFragment.TAG) .addToBackStack(ChooseFileFragment.TAG) .commit(); - - viewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class); } @OnPermissionDenied({Manifest.permission.READ_EXTERNAL_STORAGE, @@ -179,6 +183,8 @@ public void onChanged(WorkStatus workStatus) { UploadResultFragment.TAG) .addToBackStack(UploadResultFragment.TAG) .commit(); + } else { + getSupportFragmentManager().popBackStack(ChooseFileFragment.TAG, 0); } } }); @@ -203,10 +209,7 @@ public void onClick(View view) { }); snackbar .setActionTextColor(ContextCompat.getColor(MainActivity.this, R.color.dark_yellow)); - View snackBarView = snackbar.getView(); - View view = new View(this); - TextView snackTextView = snackBarView .findViewById(android.support.design.R.id.snackbar_text); snackTextView.setMaxLines(3); @@ -214,7 +217,6 @@ public void onClick(View view) { snackbar.show(); } - @Override public void onFileLoad(@NotNull LocalFile localFile) { // change the current fragment to upload @@ -227,6 +229,5 @@ public void onFileLoad(@NotNull LocalFile localFile) { UploadFileFragment.TAG); transaction.addToBackStack(UploadFileFragment.TAG); transaction.commit(); - } } \ No newline at end of file diff --git a/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/UploadHistoryActivity.kt b/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/UploadHistoryActivity.kt index 477248a..ae3cf69 100644 --- a/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/UploadHistoryActivity.kt +++ b/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/activities/UploadHistoryActivity.kt @@ -3,13 +3,17 @@ package com.thecoolguy.rumaan.fileio.ui.activities import android.arch.lifecycle.Observer import android.arch.lifecycle.ViewModelProviders import android.os.Bundle +import android.support.transition.TransitionManager import android.support.v7.app.AppCompatActivity import android.support.v7.widget.DividerItemDecoration import android.view.Menu import android.view.MenuItem import android.view.View import android.view.animation.AnimationUtils +import androidx.work.OneTimeWorkRequestBuilder +import androidx.work.WorkManager import com.thecoolguy.rumaan.fileio.R +import com.thecoolguy.rumaan.fileio.repository.ClearHistoryWorker import com.thecoolguy.rumaan.fileio.ui.UploadHistoryListAdapter import com.thecoolguy.rumaan.fileio.viewmodel.UploadHistoryViewModel import kotlinx.android.synthetic.main.activity_upload_history.* @@ -27,10 +31,18 @@ class UploadHistoryActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { android.R.id.home -> onBackPressed() + R.id.menu_clear_history -> clearHistory() } return super.onOptionsItemSelected(item) } + private fun clearHistory() { + val work = OneTimeWorkRequestBuilder() + .build() + WorkManager.getInstance() + .enqueue(work) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_upload_history) @@ -52,16 +64,18 @@ class UploadHistoryActivity : AppCompatActivity() { layoutAnimation = AnimationUtils.loadLayoutAnimation(context, R.anim.layout_anim_fall_down) } - viewModel.uploadList.observe(this, Observer { list -> + TransitionManager.beginDelayedTransition(parent_history) list?.let { progress.visibility = View.GONE - if (it.isEmpty()) + if (it.isEmpty()) { no_uploads_view.visibility = View.VISIBLE - else { + upload_history_list.visibility = View.INVISIBLE + } else { // set up recycler view and adapter adapter.swapList(list) upload_history_list.visibility = View.VISIBLE + no_uploads_view.visibility = View.INVISIBLE } } }) diff --git a/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/fragments/ChooseFileFragment.kt b/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/fragments/ChooseFileFragment.kt index 5dfc8eb..432a6be 100644 --- a/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/fragments/ChooseFileFragment.kt +++ b/app/src/main/java/com/thecoolguy/rumaan/fileio/ui/fragments/ChooseFileFragment.kt @@ -3,14 +3,12 @@ package com.thecoolguy.rumaan.fileio.ui.fragments import android.content.Context import android.os.Bundle import android.support.v4.app.Fragment -import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.Button import com.thecoolguy.rumaan.fileio.R import com.thecoolguy.rumaan.fileio.listeners.OnFragmentInteractionListener -import com.thecoolguy.rumaan.fileio.utils.MaterialIn +import kotlinx.android.synthetic.main.fragment_choose_file.* class ChooseFileFragment : Fragment() { /** @@ -23,19 +21,15 @@ class ChooseFileFragment : Fragment() { private var listener: OnFragmentInteractionListener? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? = - inflater.inflate(R.layout.fragment_choose_file, container, false) - + savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_choose_file, container, false) + } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - - MaterialIn.animate(view) - - view.findViewById