mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-21 11:28:56 -04:00
Refactor: Fix more lint errors
This commit is contained in:
parent
f8eda73ef9
commit
821c148e2c
@ -4,6 +4,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@ -28,7 +29,7 @@ public class FileItem implements Parcelable {
|
||||
private String fileName;
|
||||
private int fileStatus;
|
||||
|
||||
public FileItem(String fileName, @FileStatus int fileStatus) {
|
||||
public FileItem(@NonNull String fileName, @FileStatus int fileStatus) {
|
||||
this.fileName = fileName;
|
||||
this.fileStatus = fileStatus;
|
||||
}
|
||||
@ -40,7 +41,7 @@ public class FileItem implements Parcelable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeString(fileName);
|
||||
dest.writeInt(fileStatus);
|
||||
}
|
||||
@ -59,7 +60,7 @@ public class FileItem implements Parcelable {
|
||||
}
|
||||
};
|
||||
|
||||
public FileItem(Parcel parcel) {
|
||||
public FileItem(@NonNull Parcel parcel) {
|
||||
this.fileName = parcel.readString();
|
||||
this.fileStatus = parcel.readInt();
|
||||
}
|
||||
@ -69,7 +70,7 @@ public class FileItem implements Parcelable {
|
||||
this.fileStatus = fileStatus;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
public @NonNull String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.FileItem.Fil
|
||||
public class FileListAdapter extends RecyclerView.Adapter<FileListAdapter.FileViewHolder> {
|
||||
private final ArrayList<FileItem> fileItems;
|
||||
|
||||
public FileListAdapter(ArrayList<FileItem> fileItems) {
|
||||
public FileListAdapter(@NonNull ArrayList<FileItem> fileItems) {
|
||||
this.fileItems = fileItems;
|
||||
}
|
||||
|
||||
@ -58,7 +58,8 @@ public class FileListAdapter extends RecyclerView.Adapter<FileListAdapter.FileVi
|
||||
case ERROR:
|
||||
holder.statusImage.setImageResource(R.drawable.ic_baseline_error_24px);
|
||||
break;
|
||||
default:
|
||||
case TO_BE_SENT:
|
||||
case SENDING:
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -106,11 +106,11 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
private boolean fileTransferStarted = false;
|
||||
|
||||
private PeerGroupHandshakeAsyncTask peerGroupHandshakeAsyncTask;
|
||||
private SenderDeviceAsyncTask senderDeviceAsyncTaskArray[];
|
||||
private SenderDeviceAsyncTask[] senderDeviceAsyncTaskArray;
|
||||
private ReceiverDeviceAsyncTask receiverDeviceAsyncTask;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_local_file_transfer);
|
||||
KiwixApplication.getApplicationComponent().activityComponent()
|
||||
@ -118,6 +118,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
.build()
|
||||
.inject(this);
|
||||
ButterKnife.bind(this);
|
||||
//setTheme(sharedPreferenceUtil.nightMode() ? R.style.AddNoteDialogStyle_Night : R.style.AppTheme_Base);
|
||||
|
||||
/*
|
||||
* Presence of file Uris decides whether the device with the activity open is a sender or receiver:
|
||||
@ -180,13 +181,13 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.wifi_file_share_items, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == R.id.menu_item_search_devices) {
|
||||
|
||||
/* Permissions essential for this module */
|
||||
@ -235,7 +236,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
return this.wifiDirectManager.isWifiP2pEnabled();
|
||||
}
|
||||
|
||||
public void updateUserDevice(WifiP2pDevice userDevice) { // Update UI with user device's details
|
||||
public void updateUserDevice(@Nullable WifiP2pDevice userDevice) { // Update UI with user device's details
|
||||
wifiDirectManager.setUserDevice(userDevice);
|
||||
|
||||
if (userDevice != null) {
|
||||
@ -249,7 +250,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
((WifiPeerListAdapter) listViewPeerDevices.getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static String getDeviceStatus(int status) {
|
||||
public static @NonNull String getDeviceStatus(int status) {
|
||||
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, "Peer Status: " + status);
|
||||
switch (status) {
|
||||
@ -269,7 +270,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileName(Uri fileUri) {
|
||||
public static @NonNull String getFileName(@NonNull Uri fileUri) {
|
||||
String fileUriString = fileUri.toString();
|
||||
// Returns text after location of last slash in the file path
|
||||
return fileUriString.substring(fileUriString.lastIndexOf('/') + 1);
|
||||
@ -287,7 +288,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
textViewPeerDevices.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
public void setClientAddress(InetAddress clientAddress) {
|
||||
public void setClientAddress(@Nullable InetAddress clientAddress) {
|
||||
if (clientAddress == null) {
|
||||
// null is returned only in case of a failed handshake
|
||||
showToast(this, R.string.device_not_cooperating, Toast.LENGTH_LONG);
|
||||
@ -337,11 +338,11 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
this.totalFilesForTransfer = totalFilesForTransfer;
|
||||
}
|
||||
|
||||
public ArrayList<FileItem> getFileItems() {
|
||||
public @NonNull ArrayList<FileItem> getFileItems() {
|
||||
return filesToSend;
|
||||
}
|
||||
|
||||
public void setFileItems(ArrayList<FileItem> fileItems) {
|
||||
public void setFileItems(@NonNull ArrayList<FileItem> fileItems) {
|
||||
this.filesToSend = fileItems;
|
||||
}
|
||||
|
||||
@ -353,15 +354,15 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
return (filesSent == totalFilesForTransfer);
|
||||
}
|
||||
|
||||
public String getZimStorageRootPath() {
|
||||
public @NonNull String getZimStorageRootPath() {
|
||||
return (sharedPreferenceUtil.getPrefStorage() + "/Kiwix/");
|
||||
}
|
||||
|
||||
public InetAddress getFileReceiverDeviceAddress() {
|
||||
public @NonNull InetAddress getFileReceiverDeviceAddress() {
|
||||
return fileReceiverDeviceAddress;
|
||||
}
|
||||
|
||||
public static void copyToOutputStream(InputStream inputStream, OutputStream outputStream)
|
||||
public static void copyToOutputStream(@NonNull InputStream inputStream, @NonNull OutputStream outputStream)
|
||||
throws IOException {
|
||||
byte[] bufferForBytes = new byte[1024];
|
||||
int bytesRead;
|
||||
@ -383,7 +384,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
|
||||
/* From WifiP2pManager.PeerListListener callback-interface */
|
||||
@Override
|
||||
public void onPeersAvailable(WifiP2pDeviceList peers) {
|
||||
public void onPeersAvailable(@NonNull WifiP2pDeviceList peers) {
|
||||
searchingPeersProgressBar.setVisibility(View.GONE);
|
||||
listViewPeerDevices.setVisibility(View.VISIBLE);
|
||||
|
||||
@ -398,7 +399,7 @@ public class LocalFileTransferActivity extends AppCompatActivity
|
||||
|
||||
/* From WifiP2pManager.ConnectionInfoListener callback-interface */
|
||||
@Override
|
||||
public void onConnectionInfoAvailable(WifiP2pInfo groupInfo) {
|
||||
public void onConnectionInfoAvailable(@NonNull WifiP2pInfo groupInfo) {
|
||||
/* Devices have successfully connected, and 'info' holds information about the wifi p2p group formed */
|
||||
wifiDirectManager.setGroupInfo(groupInfo);
|
||||
|
||||
|
@ -78,11 +78,8 @@ class ReceiverDeviceAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
localFileTransferActivity.incrementTotalFilesSent();
|
||||
}
|
||||
|
||||
if (isCancelled()) {
|
||||
return false; // Returned in case the task was cancelled
|
||||
} else {
|
||||
return true; // Returned in case of a successful file transfer
|
||||
}
|
||||
return !isCancelled(); // Return true only if not cancelled
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return false; // Returned when an error was encountered during transfer
|
||||
|
@ -58,9 +58,8 @@ class SenderDeviceAsyncTask extends AsyncTask<Uri, Void, Boolean> {
|
||||
final LocalFileTransferActivity localFileTransferActivity = weakReferenceToActivity.get();
|
||||
ContentResolver contentResolver = localFileTransferActivity.getContentResolver();
|
||||
|
||||
try (Socket socket = new Socket();
|
||||
InputStream fileInputStream = contentResolver.openInputStream(
|
||||
fileUri)) { // Represents the sender device
|
||||
try (Socket socket = new Socket(); // Represents the sender device
|
||||
InputStream fileInputStream = contentResolver.openInputStream(fileUri)) {
|
||||
|
||||
if (isCancelled()) {
|
||||
return false;
|
||||
|
@ -9,6 +9,7 @@ import android.net.wifi.p2p.WifiP2pManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
|
||||
import static org.kiwix.kiwixmobile.zim_manager.local_file_transfer.LocalFileTransferActivity.showToast;
|
||||
@ -25,8 +26,8 @@ public class WifiDirectBroadcastReceiver extends BroadcastReceiver {
|
||||
private WifiP2pManager.Channel channel;
|
||||
private LocalFileTransferActivity wifiActivity;
|
||||
|
||||
public WifiDirectBroadcastReceiver(WifiP2pManager manager, WifiP2pManager.Channel channel,
|
||||
LocalFileTransferActivity activity) {
|
||||
public WifiDirectBroadcastReceiver(@NonNull WifiP2pManager manager, @NonNull WifiP2pManager.Channel channel,
|
||||
@NonNull LocalFileTransferActivity activity) {
|
||||
super();
|
||||
this.manager = manager;
|
||||
this.channel = channel;
|
||||
@ -34,7 +35,7 @@ public class WifiDirectBroadcastReceiver extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
|
||||
|
@ -26,7 +26,7 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener {
|
||||
|
||||
private static final String TAG = "WifiDirectManager";
|
||||
|
||||
private LocalFileTransferActivity activity;
|
||||
@NonNull LocalFileTransferActivity activity;
|
||||
|
||||
/* Variables related to the WiFi P2P API */
|
||||
private boolean wifiP2pEnabled = false; // Whether WiFi has been enabled or not
|
||||
@ -111,11 +111,11 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void setUserDevice(WifiP2pDevice userDevice) {
|
||||
public void setUserDevice(@NonNull WifiP2pDevice userDevice) {
|
||||
this.userDevice = userDevice;
|
||||
}
|
||||
|
||||
public void setGroupInfo(WifiP2pInfo groupInfo) {
|
||||
public void setGroupInfo(@NonNull WifiP2pInfo groupInfo) {
|
||||
this.groupInfo = groupInfo;
|
||||
}
|
||||
|
||||
@ -127,11 +127,11 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener {
|
||||
return groupInfo.isGroupOwner;
|
||||
}
|
||||
|
||||
public InetAddress getGroupOwnerAddress() {
|
||||
public @NonNull InetAddress getGroupOwnerAddress() {
|
||||
return groupInfo.groupOwnerAddress;
|
||||
}
|
||||
|
||||
public void setSenderSelectedPeerDevice(WifiP2pDevice senderSelectedPeerDevice) {
|
||||
public void setSenderSelectedPeerDevice(@NonNull WifiP2pDevice senderSelectedPeerDevice) {
|
||||
this.senderSelectedPeerDevice = senderSelectedPeerDevice;
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener {
|
||||
}
|
||||
|
||||
|
||||
public String getErrorMessage(int reason) {
|
||||
public @NonNull String getErrorMessage(int reason) {
|
||||
switch (reason) {
|
||||
case WifiP2pManager.ERROR:
|
||||
return "Internal error";
|
||||
@ -202,7 +202,7 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener {
|
||||
return "P2P unsupported on this device";
|
||||
|
||||
default:
|
||||
return "Unknown error code - " + reason;
|
||||
return ("Unknown error code - " + reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
|
||||
</vector>
|
@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
|
||||
</vector>
|
@ -49,6 +49,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Device Name"
|
||||
android:textIsSelectable="true"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_your_device"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
@ -118,16 +119,6 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!--<FrameLayout
|
||||
android:id="@+id/container_fragment_transfer_progress"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="200dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_available_device"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"/>-->
|
||||
|
||||
<View
|
||||
android:id="@+id/view_file_list_boundary"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Change Device Name"
|
||||
android:textStyle="bold"
|
||||
android:textSize="17sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_text_change_device_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Enter name"
|
||||
android:textSize="15sp"/>
|
||||
|
||||
</LinearLayout>
|
@ -13,6 +13,7 @@
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="#000000"
|
||||
android:hint="File name"
|
||||
android:textIsSelectable="true"
|
||||
android:textSize="14sp"
|
||||
android:paddingTop="1dp"
|
||||
android:paddingBottom="1dp"
|
||||
@ -41,6 +42,7 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_view_file_transferred"
|
||||
android:contentDescription="@string/status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:paddingTop="1dp"
|
||||
|
@ -11,6 +11,7 @@
|
||||
android:layout_weight="3"
|
||||
android:gravity="center_horizontal"
|
||||
android:hint="Device Name"
|
||||
android:textIsSelectable="false"
|
||||
android:textStyle="bold"
|
||||
android:textSize="17sp"
|
||||
android:paddingTop="1dp"
|
||||
|
@ -286,4 +286,5 @@
|
||||
<string name="preparing_files">Preparing files for transfer....</string>
|
||||
<string name="performing_handshake">Performing handshake....</string>
|
||||
<string name="local_zim_sharing">Local ZIM Sharing</string>
|
||||
<string name="status">Status</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user