mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 04:33:54 -04:00
Refactor: Use ButterKnife
This commit is contained in:
parent
241e2f16fa
commit
28840898e0
@ -26,6 +26,9 @@ import androidx.fragment.app.FragmentManager;
|
|||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.fragment.app.ListFragment;
|
import androidx.fragment.app.ListFragment;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.Unbinder;
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
@ -62,7 +65,13 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
private LocalFileTransferActivity localFileTransferActivity; // Parent activity, starting point of the module
|
private LocalFileTransferActivity localFileTransferActivity; // Parent activity, starting point of the module
|
||||||
private TransferProgressFragment transferProgressFragment; // Sibling fragment, for displaying transfer progress
|
private TransferProgressFragment transferProgressFragment; // Sibling fragment, for displaying transfer progress
|
||||||
|
|
||||||
private View deviceListFragmentRootView = null; // Root view corresponding to the DeviceListFragment
|
// Views part of the DeviceListFragment
|
||||||
|
@BindView(R.id.text_view_device_name) TextView deviceName;
|
||||||
|
@BindView(R.id.text_view_device_status) TextView deviceStatus;
|
||||||
|
@BindView(R.id.progress_bar_searching_peers) ProgressBar searchingPeersProgressBar;
|
||||||
|
@BindView(R.id.frame_layout_peer_devices) FrameLayout frameLayoutPeerDevices;
|
||||||
|
|
||||||
|
private Unbinder unbinder;
|
||||||
|
|
||||||
private boolean fileSender = false; // Whether file sending device or not
|
private boolean fileSender = false; // Whether file sending device or not
|
||||||
private ArrayList<Uri> fileUriList; // Uris of files to be shared, available only for the sender device
|
private ArrayList<Uri> fileUriList; // Uris of files to be shared, available only for the sender device
|
||||||
@ -104,8 +113,16 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
deviceListFragmentRootView = inflater.inflate(R.layout.fragment_device_list, null);
|
View view = inflater.inflate(R.layout.fragment_device_list, null);
|
||||||
return deviceListFragmentRootView;
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
if(unbinder != null) unbinder.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,11 +156,8 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
this.userDevice = device;
|
this.userDevice = device;
|
||||||
|
|
||||||
if(userDevice != null) {
|
if(userDevice != null) {
|
||||||
TextView deviceName = deviceListFragmentRootView.findViewById(R.id.text_view_device_name);
|
deviceName.setText(userDevice.deviceName);
|
||||||
TextView deviceStatus = deviceListFragmentRootView.findViewById(R.id.text_view_device_status);
|
deviceStatus.setText(getDeviceStatus(userDevice.status));
|
||||||
|
|
||||||
if(deviceName != null) deviceName.setText(userDevice.deviceName);
|
|
||||||
if(deviceStatus != null) deviceStatus.setText(getDeviceStatus(userDevice.status));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,10 +178,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
/* From WifiP2pManager.PeerListListener callback-interface */
|
/* From WifiP2pManager.PeerListListener callback-interface */
|
||||||
@Override
|
@Override
|
||||||
public void onPeersAvailable(WifiP2pDeviceList peers) {
|
public void onPeersAvailable(WifiP2pDeviceList peers) {
|
||||||
|
|
||||||
ProgressBar searchingPeersProgressBar = deviceListFragmentRootView.findViewById(R.id.progress_bar_searching_peers);
|
|
||||||
searchingPeersProgressBar.setVisibility(View.GONE);
|
searchingPeersProgressBar.setVisibility(View.GONE);
|
||||||
FrameLayout frameLayoutPeerDevices = deviceListFragmentRootView.findViewById(R.id.frame_layout_peer_devices);
|
|
||||||
frameLayoutPeerDevices.setVisibility(View.VISIBLE);
|
frameLayoutPeerDevices.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
peerDevices.clear();
|
peerDevices.clear();
|
||||||
@ -185,9 +196,7 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onInitiateDiscovery() { // Setup UI for searching peers
|
public void onInitiateDiscovery() { // Setup UI for searching peers
|
||||||
ProgressBar searchingPeersProgressBar = deviceListFragmentRootView.findViewById(R.id.progress_bar_searching_peers);
|
|
||||||
searchingPeersProgressBar.setVisibility(View.VISIBLE);
|
searchingPeersProgressBar.setVisibility(View.VISIBLE);
|
||||||
FrameLayout frameLayoutPeerDevices = deviceListFragmentRootView.findViewById(R.id.frame_layout_peer_devices);
|
|
||||||
frameLayoutPeerDevices.setVisibility(View.INVISIBLE);
|
frameLayoutPeerDevices.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,27 +335,38 @@ public class DeviceListFragment extends ListFragment implements WifiP2pManager.P
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
|
|
||||||
View rowView = convertView;
|
View rowView = convertView;
|
||||||
|
ViewHolder viewHolder;
|
||||||
|
|
||||||
if(rowView == null) {
|
if(rowView == null) {
|
||||||
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
|
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
|
||||||
rowView = layoutInflater.inflate(R.layout.row_peer_device, parent, false);
|
rowView = layoutInflater.inflate(R.layout.row_peer_device, parent, false);
|
||||||
|
viewHolder = new ViewHolder(rowView);
|
||||||
|
rowView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ViewHolder) rowView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiP2pDevice device = listItems.get(position);
|
WifiP2pDevice device = listItems.get(position);
|
||||||
|
|
||||||
if(device != null) {
|
if(device != null) {
|
||||||
TextView deviceName = rowView.findViewById(R.id.row_device_name);
|
viewHolder.deviceName.setText(device.deviceName);
|
||||||
TextView deviceStatus = rowView.findViewById(R.id.row_device_status);
|
viewHolder.deviceStatus.setText(getDeviceStatus(device.status));
|
||||||
|
|
||||||
if(deviceName != null) deviceName.setText(device.deviceName);
|
|
||||||
if(deviceStatus != null) deviceStatus.setText(getDeviceStatus(device.status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowView;
|
return rowView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ViewHolder {
|
||||||
|
@BindView(R.id.row_device_name) TextView deviceName;
|
||||||
|
@BindView(R.id.row_device_status) TextView deviceStatus;
|
||||||
|
|
||||||
|
public ViewHolder(View view) {
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface DeviceActionListener {
|
public interface DeviceActionListener {
|
||||||
void cancelSearch();
|
void cancelSearch();
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
package org.kiwix.kiwixmobile.zim_manager.local_file_transfer;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -34,6 +33,8 @@ import androidx.fragment.app.DialogFragment;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
@ -64,6 +65,8 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
@Inject
|
@Inject
|
||||||
SharedPreferenceUtil sharedPreferenceUtil;
|
SharedPreferenceUtil sharedPreferenceUtil;
|
||||||
|
|
||||||
|
@BindView(R.id.toolbar_local_file_transfer) Toolbar actionBar;
|
||||||
|
|
||||||
private ArrayList<Uri> fileUriArrayList; // For sender device, stores Uris of files to be transferred
|
private ArrayList<Uri> fileUriArrayList; // For sender device, stores Uris of files to be transferred
|
||||||
private Boolean fileSendingDevice = false;// Whether the device is the file sender or not
|
private Boolean fileSendingDevice = false;// Whether the device is the file sender or not
|
||||||
|
|
||||||
@ -85,6 +88,7 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
setContentView(R.layout.activity_local_file_transfer);
|
setContentView(R.layout.activity_local_file_transfer);
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Protect AsyncTask from orientation changes
|
||||||
KiwixApplication.getApplicationComponent().inject(this);
|
KiwixApplication.getApplicationComponent().inject(this);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Presence of file Uris decides whether the device with the activity open is a sender or receiver:
|
* Presence of file Uris decides whether the device with the activity open is a sender or receiver:
|
||||||
@ -99,7 +103,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements Wifi
|
|||||||
setDeviceAsFileSender();
|
setDeviceAsFileSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
Toolbar actionBar = findViewById(R.id.toolbar_local_file_transfer);
|
|
||||||
setSupportActionBar(actionBar);
|
setSupportActionBar(actionBar);
|
||||||
actionBar.setNavigationIcon(R.drawable.ic_close_white_24dp);
|
actionBar.setNavigationIcon(R.drawable.ic_close_white_24dp);
|
||||||
actionBar.setNavigationOnClickListener(new View.OnClickListener(){
|
actionBar.setNavigationOnClickListener(new View.OnClickListener(){
|
||||||
|
@ -10,6 +10,9 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.Unbinder;
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -21,8 +24,10 @@ import java.util.ArrayList;
|
|||||||
* */
|
* */
|
||||||
public class TransferProgressFragment extends Fragment {
|
public class TransferProgressFragment extends Fragment {
|
||||||
|
|
||||||
|
@BindView(R.id.recycler_view_transfer_files) RecyclerView filesRecyclerView;
|
||||||
|
private Unbinder unbinder;
|
||||||
|
|
||||||
private ArrayList<FileItem> fileItems;
|
private ArrayList<FileItem> fileItems;
|
||||||
private RecyclerView filesRecyclerView;
|
|
||||||
private FileListAdapter fileListAdapter;
|
private FileListAdapter fileListAdapter;
|
||||||
|
|
||||||
public TransferProgressFragment() {
|
public TransferProgressFragment() {
|
||||||
@ -36,8 +41,7 @@ public class TransferProgressFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_transfer_progress, container, false);
|
View view = inflater.inflate(R.layout.fragment_transfer_progress, container, false);
|
||||||
|
unbinder = ButterKnife.bind(this, view);
|
||||||
filesRecyclerView = view.findViewById(R.id.recycler_view_transfer_files);
|
|
||||||
|
|
||||||
fileListAdapter = new FileListAdapter(getActivity(), fileItems);
|
fileListAdapter = new FileListAdapter(getActivity(), fileItems);
|
||||||
filesRecyclerView.setAdapter(fileListAdapter);
|
filesRecyclerView.setAdapter(fileListAdapter);
|
||||||
@ -47,6 +51,12 @@ public class TransferProgressFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
if(unbinder != null) unbinder.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
public void changeStatus(int itemIndex, short status) {
|
public void changeStatus(int itemIndex, short status) {
|
||||||
fileItems.get(itemIndex).setFileStatus(status);
|
fileItems.get(itemIndex).setFileStatus(status);
|
||||||
fileListAdapter.notifyItemChanged(itemIndex);
|
fileListAdapter.notifyItemChanged(itemIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user