allow removing extra timezones by long pressing too

This commit is contained in:
tibbi 2018-03-01 22:35:43 +01:00
parent eeb8b29e0f
commit 133a3717f0
3 changed files with 28 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.clock.R
import com.simplemobiletools.clock.activities.SimpleActivity
import com.simplemobiletools.clock.extensions.config
import com.simplemobiletools.clock.extensions.getFormattedDate
import com.simplemobiletools.clock.models.MyTimeZone
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
@ -29,7 +30,15 @@ class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTime
view?.time_zone_frame?.isSelected = select
}
override fun actionItemPressed(id: Int) {}
override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) {
return
}
when (id) {
R.id.cab_remove -> removeItems()
}
}
override fun getSelectableItemCount() = timeZones.size
@ -55,6 +64,23 @@ class TimeZonesAdapter(activity: SimpleActivity, var timeZones: ArrayList<MyTime
notifyDataSetChanged()
}
private fun removeItems() {
val timeZonesToRemove = ArrayList<MyTimeZone>()
val timeZoneIDsToRemove = ArrayList<String>()
selectedPositions.sortedDescending().forEach {
val timeZone = timeZones[it]
timeZonesToRemove.add(timeZone)
timeZoneIDsToRemove.add(timeZone.id.toString())
}
timeZones.removeAll(timeZonesToRemove)
removeSelectedItems()
val selectedTimeZones = activity.config.selectedTimeZones
val newTimeZones = selectedTimeZones.filter { !timeZoneIDsToRemove.contains(it) }.toHashSet()
activity.config.selectedTimeZones = newTimeZones
}
private fun setupView(view: View, timeZone: MyTimeZone) {
val calendar = Calendar.getInstance(TimeZone.getTimeZone(timeZone.zoneName))
val offset = calendar.timeZone.rawOffset

View File

@ -18,7 +18,7 @@
android:gravity="center_vertical"
android:maxLines="1"
android:padding="@dimen/activity_margin"
android:textSize="@dimen/normal_text_size"
android:textSize="@dimen/bigger_text_size"
tools:text="GMT-11:00 Midway"/>
<com.simplemobiletools.commons.views.MyAppCompatCheckbox

View File

@ -6,11 +6,6 @@
android:icon="@drawable/ic_rename"
android:title="@string/rename"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_select_all"
android:icon="@drawable/ic_select_all"
android:title="@string/select_all"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_remove"
android:icon="@drawable/ic_minus_circle"