mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
convert ChangeSortingDialog to kotlin
This commit is contained in:
parent
fd0bf3fce4
commit
8cc9c27416
5 changed files with 103 additions and 115 deletions
|
@ -32,7 +32,7 @@ import com.simplemobiletools.gallery.R;
|
|||
import com.simplemobiletools.gallery.Utils;
|
||||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter;
|
||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask;
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSorting;
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog;
|
||||
import com.simplemobiletools.gallery.dialogs.CopyDialog;
|
||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog;
|
||||
import com.simplemobiletools.gallery.models.Directory;
|
||||
|
@ -51,7 +51,7 @@ import butterknife.ButterKnife;
|
|||
|
||||
public class MainActivity extends SimpleActivity
|
||||
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener,
|
||||
SwipeRefreshLayout.OnRefreshListener, ChangeSorting.ChangeDialogListener, GetDirectoriesAsynctask.GetDirectoriesListener {
|
||||
SwipeRefreshLayout.OnRefreshListener, GetDirectoriesAsynctask.GetDirectoriesListener {
|
||||
@BindView(R.id.directories_grid) GridView mGridView;
|
||||
@BindView(R.id.directories_holder) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
||||
|
@ -180,7 +180,12 @@ public class MainActivity extends SimpleActivity
|
|||
}
|
||||
|
||||
private void showSortingDialog() {
|
||||
new ChangeSorting(this, true);
|
||||
new ChangeSortingDialog(this, true, new ChangeSortingDialog.OnChangeSortingListener() {
|
||||
@Override
|
||||
public void sortingChanged() {
|
||||
getDirectories();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void prepareForDeleting() {
|
||||
|
@ -585,11 +590,6 @@ public class MainActivity extends SimpleActivity
|
|||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortingDialogClosed() {
|
||||
getDirectories();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gotDirectories(@NotNull ArrayList<Directory> dirs) {
|
||||
mIsGettingDirs = false;
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.simplemobiletools.gallery.Constants;
|
|||
import com.simplemobiletools.gallery.R;
|
||||
import com.simplemobiletools.gallery.Utils;
|
||||
import com.simplemobiletools.gallery.adapters.MediaAdapter;
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSorting;
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog;
|
||||
import com.simplemobiletools.gallery.dialogs.CopyDialog;
|
||||
import com.simplemobiletools.gallery.models.Medium;
|
||||
|
||||
|
@ -51,7 +51,7 @@ import butterknife.ButterKnife;
|
|||
|
||||
public class MediaActivity extends SimpleActivity
|
||||
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener,
|
||||
SwipeRefreshLayout.OnRefreshListener, ChangeSorting.ChangeDialogListener {
|
||||
SwipeRefreshLayout.OnRefreshListener {
|
||||
private static final String TAG = MediaActivity.class.getSimpleName();
|
||||
@BindView(R.id.media_grid) GridView mGridView;
|
||||
@BindView(R.id.media_holder) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
@ -168,7 +168,12 @@ public class MediaActivity extends SimpleActivity
|
|||
}
|
||||
|
||||
private void showSortingDialog() {
|
||||
new ChangeSorting(this, false);
|
||||
new ChangeSortingDialog(this, false, new ChangeSortingDialog.OnChangeSortingListener() {
|
||||
@Override
|
||||
public void sortingChanged() {
|
||||
initializeGallery();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void hideDirectory() {
|
||||
|
@ -549,9 +554,4 @@ public class MediaActivity extends SimpleActivity
|
|||
initializeGallery();
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortingDialogClosed() {
|
||||
initializeGallery();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
package com.simplemobiletools.gallery.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import com.simplemobiletools.gallery.Config;
|
||||
import com.simplemobiletools.gallery.Constants;
|
||||
import com.simplemobiletools.gallery.R;
|
||||
|
||||
public class ChangeSorting extends AlertDialog.Builder implements DialogInterface.OnClickListener {
|
||||
private static Config mConfig;
|
||||
private static ChangeDialogListener mListener;
|
||||
private static View mHolder;
|
||||
|
||||
private static int mCurrSorting;
|
||||
private static boolean mIsDirectorySorting;
|
||||
|
||||
public ChangeSorting(Activity act, boolean isDirectorySorting) {
|
||||
super(act.getApplicationContext());
|
||||
|
||||
mIsDirectorySorting = isDirectorySorting;
|
||||
mListener = (ChangeDialogListener) act;
|
||||
mConfig = Config.Companion.newInstance(getContext());
|
||||
mHolder = act.getLayoutInflater().inflate(R.layout.change_sorting, null);
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
||||
builder.setTitle(act.getResources().getString(R.string.sort_by));
|
||||
builder.setView(mHolder);
|
||||
|
||||
mCurrSorting = (mIsDirectorySorting ? mConfig.getDirectorySorting() : mConfig.getSorting());
|
||||
setupSortRadio();
|
||||
setupOrderRadio();
|
||||
|
||||
builder.setPositiveButton(R.string.ok, this);
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void setupSortRadio() {
|
||||
final RadioGroup sortingRadio = (RadioGroup) mHolder.findViewById(R.id.dialog_radio_sorting);
|
||||
RadioButton sortBtn = (RadioButton) sortingRadio.findViewById(R.id.dialog_radio_name);
|
||||
if ((mCurrSorting & Constants.SORT_BY_DATE) != 0) {
|
||||
sortBtn = (RadioButton) sortingRadio.findViewById(R.id.dialog_radio_date);
|
||||
} else if ((mCurrSorting & Constants.SORT_BY_SIZE) != 0) {
|
||||
sortBtn = (RadioButton) sortingRadio.findViewById(R.id.dialog_radio_size);
|
||||
}
|
||||
sortBtn.setChecked(true);
|
||||
}
|
||||
|
||||
private void setupOrderRadio() {
|
||||
final RadioGroup orderRadio = (RadioGroup) mHolder.findViewById(R.id.dialog_radio_order);
|
||||
RadioButton orderBtn = (RadioButton) orderRadio.findViewById(R.id.dialog_radio_ascending);
|
||||
if ((mCurrSorting & Constants.SORT_DESCENDING) != 0) {
|
||||
orderBtn = (RadioButton) orderRadio.findViewById(R.id.dialog_radio_descending);
|
||||
}
|
||||
orderBtn.setChecked(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
final RadioGroup sortingRadio = (RadioGroup) mHolder.findViewById(R.id.dialog_radio_sorting);
|
||||
int sorting = Constants.SORT_BY_NAME;
|
||||
switch (sortingRadio.getCheckedRadioButtonId()) {
|
||||
case R.id.dialog_radio_date:
|
||||
sorting = Constants.SORT_BY_DATE;
|
||||
break;
|
||||
case R.id.dialog_radio_size:
|
||||
sorting = Constants.SORT_BY_SIZE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
final RadioGroup orderRadio = (RadioGroup) mHolder.findViewById(R.id.dialog_radio_order);
|
||||
if (orderRadio.getCheckedRadioButtonId() == R.id.dialog_radio_descending) {
|
||||
sorting |= Constants.SORT_DESCENDING;
|
||||
}
|
||||
|
||||
if (mIsDirectorySorting) {
|
||||
if (mConfig.getDirectorySorting() != sorting) {
|
||||
mConfig.setDirectorySorting(sorting);
|
||||
}
|
||||
} else {
|
||||
if (mConfig.getSorting() != sorting) {
|
||||
mConfig.setSorting(sorting);
|
||||
}
|
||||
}
|
||||
mListener.sortingDialogClosed();
|
||||
}
|
||||
|
||||
public interface ChangeDialogListener {
|
||||
void sortingDialogClosed();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package com.simplemobiletools.gallery.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import com.simplemobiletools.gallery.Config
|
||||
import com.simplemobiletools.gallery.Constants
|
||||
import com.simplemobiletools.gallery.R
|
||||
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||
|
||||
class ChangeSortingDialog(val activity: Activity, val isDirectorySorting: Boolean, val listener: OnChangeSortingListener) : DialogInterface.OnClickListener {
|
||||
companion object {
|
||||
private var currSorting = 0
|
||||
|
||||
lateinit var config: Config
|
||||
lateinit var view: View
|
||||
}
|
||||
|
||||
init {
|
||||
config = Config.newInstance(activity)
|
||||
view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null)
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle(activity.resources.getString(R.string.sort_by))
|
||||
.setView(view)
|
||||
.setPositiveButton(R.string.ok, this)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create()
|
||||
.show()
|
||||
|
||||
currSorting = if (isDirectorySorting) config.directorySorting else config.sorting
|
||||
setupSortRadio()
|
||||
setupOrderRadio()
|
||||
}
|
||||
|
||||
private fun setupSortRadio() {
|
||||
val sortingRadio = view.dialog_radio_sorting
|
||||
var sortBtn = sortingRadio.dialog_radio_name
|
||||
|
||||
if (currSorting and Constants.SORT_BY_DATE != 0) {
|
||||
sortBtn = sortingRadio.dialog_radio_date
|
||||
} else if (currSorting and Constants.SORT_BY_SIZE != 0) {
|
||||
sortBtn = sortingRadio.dialog_radio_size
|
||||
}
|
||||
sortBtn.isChecked = true
|
||||
}
|
||||
|
||||
private fun setupOrderRadio() {
|
||||
val orderRadio = view.dialog_radio_order
|
||||
var orderBtn = orderRadio.dialog_radio_ascending
|
||||
|
||||
if (currSorting and Constants.SORT_DESCENDING != 0) {
|
||||
orderBtn = orderRadio.dialog_radio_descending
|
||||
}
|
||||
orderBtn.isChecked = true
|
||||
}
|
||||
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
val sortingRadio = view.dialog_radio_sorting
|
||||
var sorting = when (sortingRadio.checkedRadioButtonId) {
|
||||
R.id.dialog_radio_name -> Constants.SORT_BY_NAME
|
||||
R.id.dialog_radio_date -> Constants.SORT_BY_DATE
|
||||
else -> Constants.SORT_BY_SIZE
|
||||
}
|
||||
|
||||
if (view.dialog_radio_order.checkedRadioButtonId == R.id.dialog_radio_descending) {
|
||||
sorting = sorting or Constants.SORT_DESCENDING
|
||||
}
|
||||
|
||||
if (isDirectorySorting) {
|
||||
if (config.directorySorting != sorting) {
|
||||
config.directorySorting = sorting
|
||||
}
|
||||
} else {
|
||||
if (config.sorting != sorting) {
|
||||
config.sorting = sorting
|
||||
}
|
||||
}
|
||||
listener.sortingChanged()
|
||||
}
|
||||
|
||||
interface OnChangeSortingListener {
|
||||
fun sortingChanged()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue