mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Allow MultiSelection in ZimHostActivity
This commit is contained in:
parent
635bc4ee8d
commit
a8f30c28af
@ -41,6 +41,7 @@ import com.google.android.gms.location.LocationSettingsStatusCodes;
|
|||||||
import com.google.android.gms.tasks.Task;
|
import com.google.android.gms.tasks.Task;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
@ -48,7 +49,9 @@ import org.kiwix.kiwixmobile.R;
|
|||||||
import org.kiwix.kiwixmobile.base.BaseActivity;
|
import org.kiwix.kiwixmobile.base.BaseActivity;
|
||||||
import org.kiwix.kiwixmobile.main.MainActivity;
|
import org.kiwix.kiwixmobile.main.MainActivity;
|
||||||
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotService;
|
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotService;
|
||||||
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.SelectionMode;
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BookOnDiskDelegate;
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BookOnDiskDelegate;
|
||||||
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter;
|
||||||
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BooksOnDiskListItem;
|
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.adapter.BooksOnDiskListItem;
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||||
@ -77,7 +80,7 @@ public class ZimHostActivity extends BaseActivity implements
|
|||||||
private static final int LOCATION_SETTINGS_PERMISSION_RESULT = 101;
|
private static final int LOCATION_SETTINGS_PERMISSION_RESULT = 101;
|
||||||
private Intent serviceIntent;
|
private Intent serviceIntent;
|
||||||
private Task<LocationSettingsResponse> task;
|
private Task<LocationSettingsResponse> task;
|
||||||
private ZimHostAdapter booksAdapter;
|
BooksOnDiskAdapter booksAdapter;
|
||||||
HotspotService hotspotService;
|
HotspotService hotspotService;
|
||||||
String ip;
|
String ip;
|
||||||
boolean bound;
|
boolean bound;
|
||||||
@ -97,15 +100,20 @@ public class ZimHostActivity extends BaseActivity implements
|
|||||||
startServerButton.setText(getString(R.string.stop_server_label));
|
startServerButton.setText(getString(R.string.stop_server_label));
|
||||||
startServerButton.setBackgroundColor(getResources().getColor(R.color.stopServer));
|
startServerButton.setBackgroundColor(getResources().getColor(R.color.stopServer));
|
||||||
}
|
}
|
||||||
|
BookOnDiskDelegate.BookDelegate bookDelegate =
|
||||||
booksAdapter = new ZimHostAdapter(
|
|
||||||
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
new BookOnDiskDelegate.BookDelegate(sharedPreferenceUtil,
|
||||||
bookOnDiskItem -> {
|
bookOnDiskItem -> {
|
||||||
open(bookOnDiskItem);
|
open(bookOnDiskItem);
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
null),
|
bookOnDiskItem -> {
|
||||||
|
select(bookOnDiskItem);
|
||||||
|
return Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
bookDelegate.setSelectionMode(SelectionMode.MULTI);
|
||||||
|
booksAdapter = new BooksOnDiskAdapter(bookDelegate
|
||||||
|
,
|
||||||
BookOnDiskDelegate.LanguageDelegate.INSTANCE
|
BookOnDiskDelegate.LanguageDelegate.INSTANCE
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -135,6 +143,9 @@ public class ZimHostActivity extends BaseActivity implements
|
|||||||
|
|
||||||
startServerButton.setOnClickListener(new View.OnClickListener() {
|
startServerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override public void onClick(View v) {
|
@Override public void onClick(View v) {
|
||||||
|
|
||||||
|
//Get File Path of All The ZIMs using booksAdapter
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
toggleHotspot();
|
toggleHotspot();
|
||||||
} else {
|
} else {
|
||||||
@ -161,6 +172,20 @@ public class ZimHostActivity extends BaseActivity implements
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void select(BooksOnDiskListItem.BookOnDisk bookOnDisk) {
|
||||||
|
ArrayList<BooksOnDiskListItem> booksList = new ArrayList<>();
|
||||||
|
booksList.addAll(booksAdapter.getItems());
|
||||||
|
int i = 0;
|
||||||
|
for (BooksOnDiskListItem item : booksAdapter.getItems()) {
|
||||||
|
if (item.equals(bookOnDisk)) {
|
||||||
|
booksList.get(i).setSelected(!bookOnDisk.isSelected());
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
booksAdapter.setItems(booksList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override protected void onStart() {
|
@Override protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
bindService();
|
bindService();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user