forked from x0b/rcx
-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds option to exclude file/folder patterns #224
Open
kajgies
wants to merge
9
commits into
newhinton:master
Choose a base branch
from
kajgies:feature/exclude_patterns
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d63c6dd
Adds option to exclude file/folder patterns
51855cc
Adds filters as a new table
83ec617
Fixes filter spinner not appearing after creating first filter
1564c21
Adds import/export support for filters
f5f92ba
Fixes dark mode for the filterentry
b8021b5
Turns filterId into a constant
63f347e
Fixes accidental renames and some invalid layout params
f4a31a8
Removes unnecessary framelayout
982a9f9
Merge remote-tracking branch 'origin/master' into feature/exclude_pat…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
141 changes: 141 additions & 0 deletions
141
app/src/main/java/ca/pkay/rcloneexplorer/Activities/FilterActivity.kt
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,141 @@ | ||
package ca.pkay.rcloneexplorer.Activities | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.appcompat.widget.Toolbar | ||
import androidx.core.view.size | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import ca.pkay.rcloneexplorer.Database.DatabaseHandler | ||
import ca.pkay.rcloneexplorer.Items.Filter | ||
import ca.pkay.rcloneexplorer.Items.FilterEntry | ||
import ca.pkay.rcloneexplorer.R | ||
import ca.pkay.rcloneexplorer.Rclone | ||
import ca.pkay.rcloneexplorer.RecyclerViewAdapters.FilterEntryRecyclerViewAdapter | ||
import ca.pkay.rcloneexplorer.util.ActivityHelper | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
import es.dmoral.toasty.Toasty | ||
import jp.wasabeef.recyclerview.animators.LandingAnimator | ||
|
||
class FilterActivity : AppCompatActivity() { | ||
|
||
|
||
private lateinit var rcloneInstance: Rclone | ||
private lateinit var dbHandler: DatabaseHandler | ||
|
||
private lateinit var filterTitle: EditText | ||
private lateinit var filterList: RecyclerView | ||
|
||
|
||
private var existingFilter: Filter? = null | ||
private var filters: ArrayList<FilterEntry> = arrayListOf() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
ActivityHelper.applyTheme(this) | ||
setContentView(R.layout.activity_filter) | ||
val toolbar = findViewById<Toolbar>(R.id.toolbar) | ||
setSupportActionBar(toolbar) | ||
val actionBar = supportActionBar | ||
actionBar?.setDisplayHomeAsUpEnabled(true) | ||
|
||
filterTitle = findViewById(R.id.filter_title_textfield) | ||
filterList = findViewById(R.id.filter_filterlist) | ||
val newFilterEntry = findViewById<Button>(R.id.filter_add_filterentry_button) | ||
newFilterEntry.setOnClickListener { | ||
filters.add(FilterEntry(FilterEntry.FILTER_EXCLUDE, "")) | ||
filterList.adapter?.notifyItemInserted(filterList.size) | ||
} | ||
|
||
|
||
rcloneInstance = Rclone(this) | ||
dbHandler = DatabaseHandler(this) | ||
val extras = intent.extras | ||
val filterId: Long | ||
if (extras != null) { | ||
filterId = extras.getLong(ID_EXTRA) | ||
if (filterId != 0L) { | ||
existingFilter = dbHandler.getFilter(filterId) | ||
if (existingFilter == null) { | ||
Toasty.error( | ||
this, | ||
this.resources.getString(R.string.filteractivity_filter_not_found) | ||
).show() | ||
finish() | ||
} | ||
} | ||
} | ||
val fab = findViewById<FloatingActionButton>(R.id.saveButton) | ||
fab.setOnClickListener { | ||
if (existingFilter == null) { | ||
saveFilter() | ||
} else { | ||
persistFilterChanges() | ||
} | ||
} | ||
|
||
if(existingFilter != null) { | ||
filters = existingFilter!!.getFilters() | ||
} | ||
filterTitle.setText(existingFilter?.title) | ||
prepareFilterList() | ||
} | ||
|
||
override fun onSupportNavigateUp(): Boolean { | ||
finish() | ||
return true | ||
} | ||
|
||
private fun persistFilterChanges() { | ||
val updatedFilter = getFilterValues(existingFilter!!.id) | ||
if (updatedFilter != null) { | ||
dbHandler.updateFilter(updatedFilter) | ||
val resultIntent = Intent() | ||
resultIntent.putExtra(SAVED_FILTER_ID_EXTRA, updatedFilter.id) | ||
setResult(Activity.RESULT_OK, resultIntent) | ||
finish() | ||
} | ||
} | ||
|
||
private fun saveFilter() { | ||
val newFilter = getFilterValues(0) | ||
if (newFilter != null) { | ||
val filter = dbHandler.createFilter(newFilter) | ||
val resultIntent = Intent() | ||
resultIntent.putExtra(SAVED_FILTER_ID_EXTRA, filter.id) | ||
setResult(Activity.RESULT_OK, resultIntent) | ||
finish() | ||
} | ||
} | ||
|
||
private fun getFilterValues(id: Long): Filter? { | ||
val filterToPopulate = Filter(id) | ||
filterToPopulate.title = filterTitle.text.toString() | ||
filterToPopulate.setFilters(filters) | ||
if (filterTitle.text.toString() == "") { | ||
Toasty.error( | ||
this.applicationContext, | ||
getString(R.string.filter_data_validation_error_no_title), | ||
Toast.LENGTH_SHORT, | ||
true | ||
).show() | ||
return null | ||
} | ||
return filterToPopulate | ||
} | ||
private fun prepareFilterList() { | ||
val adapter = FilterEntryRecyclerViewAdapter(filters, this) | ||
filterList.layoutManager = LinearLayoutManager(this) | ||
filterList.itemAnimator = LandingAnimator() | ||
filterList.adapter = adapter | ||
} | ||
companion object { | ||
const val ID_EXTRA = "FILTER_EDIT_ID" | ||
const val SAVED_FILTER_ID_EXTRA = "filterId" | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a "close" icon in the toolbar would be better instead of the "back"-one that is default. In the future i might change views like this to a Full Screen Dialog