adding a Settings button for emptying the recycle bin

This commit is contained in:
tibbi 2018-06-27 18:50:30 +02:00
parent b0c4ba7d99
commit 317089a4ff
3 changed files with 34 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.dialogs.ManageExtendedDetailsDialog import com.simplemobiletools.gallery.dialogs.ManageExtendedDetailsDialog
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.emptyTheRecycleBin
import com.simplemobiletools.gallery.helpers.ROTATE_BY_ASPECT_RATIO import com.simplemobiletools.gallery.helpers.ROTATE_BY_ASPECT_RATIO
import com.simplemobiletools.gallery.helpers.ROTATE_BY_DEVICE_ROTATION import com.simplemobiletools.gallery.helpers.ROTATE_BY_DEVICE_ROTATION
import com.simplemobiletools.gallery.helpers.ROTATE_BY_SYSTEM_SETTING import com.simplemobiletools.gallery.helpers.ROTATE_BY_SYSTEM_SETTING
@ -71,6 +72,7 @@ class SettingsActivity : SimpleActivity() {
updateTextColors(settings_holder) updateTextColors(settings_holder)
setupSectionColors() setupSectionColors()
setupUseRecycleBin() setupUseRecycleBin()
setupEmptyRecycleBin()
} }
private fun setupSectionColors() { private fun setupSectionColors() {
@ -412,10 +414,18 @@ class SettingsActivity : SimpleActivity() {
}) })
private fun setupUseRecycleBin() { private fun setupUseRecycleBin() {
settings_empty_recycle_bin_holder.beVisibleIf(config.useRecycleBin)
settings_use_recycle_bin.isChecked = config.useRecycleBin settings_use_recycle_bin.isChecked = config.useRecycleBin
settings_use_recycle_bin_holder.setOnClickListener { settings_use_recycle_bin_holder.setOnClickListener {
settings_use_recycle_bin.toggle() settings_use_recycle_bin.toggle()
config.useRecycleBin = settings_use_recycle_bin.isChecked config.useRecycleBin = settings_use_recycle_bin.isChecked
settings_empty_recycle_bin_holder.beVisibleIf(config.useRecycleBin)
}
}
private fun setupEmptyRecycleBin() {
settings_empty_recycle_bin_holder.setOnClickListener {
emptyTheRecycleBin()
} }
} }
} }

View file

@ -205,13 +205,13 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback:
}.start() }.start()
} }
fun BaseSimpleActivity.emptyTheRecycleBin(callback: () -> Unit) { fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
Thread { Thread {
filesDir.deleteRecursively() filesDir.deleteRecursively()
galleryDB.MediumDao().clearRecycleBin() galleryDB.MediumDao().clearRecycleBin()
galleryDB.DirectoryDao().deleteRecycleBin() galleryDB.DirectoryDao().deleteRecycleBin()
toast(R.string.recycle_bin_emptied) toast(R.string.recycle_bin_emptied)
callback() callback?.invoke()
}.start() }.start()
} }

View file

@ -982,5 +982,27 @@
android:text="@string/move_items_into_recycle_bin"/> android:text="@string/move_items_into_recycle_bin"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_empty_recycle_bin_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_empty_recycle_bin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/empty_recycle_bin"/>
</RelativeLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>