Skip to content

Commit

Permalink
- Clear history
Browse files Browse the repository at this point in the history
 - Move back to first fragment after upload chosen
  • Loading branch information
rumaan committed Jun 11, 2018
1 parent 678e2d6 commit af6101c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 30 deletions.
Binary file modified app/build/outputs/apk/debug/app-debug.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void accept(FileEntity fileEntity) {

assertEquals(items, database.uploadItemDao().numberOfItems());

List<FileEntity> list = database.uploadItemDao().allUploads();
List<FileEntity> list = database.uploadItemDao().getAllUploads().getValue();
assertNotNull(list);
assertEquals(fileEntities, list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ 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();

@Query("SELECT * FROM " + TABLE_NAME)
LiveData<List<FileEntity>> getAllUploads();

@Query("SELECT * FROM " + TABLE_NAME)
List<FileEntity> allUploads();
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -179,6 +183,8 @@ public void onChanged(WorkStatus workStatus) {
UploadResultFragment.TAG)
.addToBackStack(UploadResultFragment.TAG)
.commit();
} else {
getSupportFragmentManager().popBackStack(ChooseFileFragment.TAG, 0);
}
}
});
Expand All @@ -203,18 +209,14 @@ 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);

snackbar.show();
}


@Override
public void onFileLoad(@NotNull LocalFile localFile) {
// change the current fragment to upload
Expand All @@ -227,6 +229,5 @@ public void onFileLoad(@NotNull LocalFile localFile) {
UploadFileFragment.TAG);
transaction.addToBackStack(UploadFileFragment.TAG);
transaction.commit();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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<ClearHistoryWorker>()
.build()
WorkManager.getInstance()
.enqueue(work)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_upload_history)
Expand All @@ -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
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
/**
Expand All @@ -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<Button>(R.id.btn_choose_file)
.setOnClickListener {
buttonChooseFileClick()
}
btn_choose_file.setOnClickListener {
buttonChooseFileClick()
}
}

override fun onAttach(context: Context) {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/anim/item_anim_slide_up_fade.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
android:duration="500"
>
<translate
android:fromYDelta="45%"
android:fromYDelta="50%"
android:interpolator="@android:interpolator/decelerate_cubic"
android:toYDelta="0"/>
<alpha
android:fromAlpha="0"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_upload_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent_history"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.thecoolguy.rumaan.fileio.ui.activities.UploadHistoryActivity">
Expand Down

0 comments on commit af6101c

Please sign in to comment.