Skip to content

Commit 3601e37

Browse files
committed
Replace the deprecated Fragment calls using androidx
1 parent 1ed97ca commit 3601e37

19 files changed

+101
-108
lines changed

App/src/main/java/org/astonbitecode/rustkeylock/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
1616
package org.astonbitecode.rustkeylock;
1717

18-
import android.app.Activity;
1918
import android.os.Bundle;
2019
import android.util.Log;
20+
import androidx.fragment.app.FragmentActivity;
2121
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandlable;
2222
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
2323

24-
public class MainActivity extends Activity implements BackButtonHandlable {
24+
public class MainActivity extends FragmentActivity implements BackButtonHandlable {
2525
private static MainActivity ACTIVE_ACTIVITY;
2626

2727
public static MainActivity getActiveActivity() {

App/src/main/java/org/astonbitecode/rustkeylock/api/InterfaceWithRust.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
1616
package org.astonbitecode.rustkeylock.api;
1717

18-
import android.app.Fragment;
18+
import androidx.fragment.app.Fragment;
1919
import android.util.Log;
2020
import org.astonbitecode.rustkeylock.api.stubs.GuiResponse;
2121

App/src/main/java/org/astonbitecode/rustkeylock/callbacks/EditConfigurationCb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public UiThreadRunnable(List<String> strings, MainActivity mainActivity) {
5050
public void run() {
5151
EditConfiguration ec = new EditConfiguration(strings);
5252
mainActivity.setBackButtonHandler(ec);
53-
mainActivity.getFragmentManager().beginTransaction().replace(R.id.container, ec).commitAllowingStateLoss();
53+
mainActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container, ec).commitAllowingStateLoss();
5454
InterfaceWithRust.INSTANCE.updateState(ec);
5555
}
5656
}

App/src/main/java/org/astonbitecode/rustkeylock/callbacks/ShowEntriesSetCb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public UiThreadRunnable(List<JavaEntry> entries, String filter, MainActivity mai
5555
public void run() {
5656
ListEntries le = new ListEntries(entries, filter);
5757
mainActivity.setBackButtonHandler(le);
58-
mainActivity.getFragmentManager().beginTransaction().replace(R.id.container, le).commitAllowingStateLoss();
58+
mainActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container, le).commitAllowingStateLoss();
5959
InterfaceWithRust.INSTANCE.updateState(le);
6060
}
6161
}

App/src/main/java/org/astonbitecode/rustkeylock/callbacks/ShowEntryCb.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public CompletableFuture<Object> apply(JavaEntry anEntry, Integer entryIndex, Bo
3636
return f;
3737
}
3838

39-
private class UiThreadRunnable implements Runnable {
40-
private MainActivity mainActivity = null;
41-
private JavaEntry entry = null;
42-
private int entryIndex;
43-
private boolean edit = false;
44-
private boolean delete = false;
39+
private static class UiThreadRunnable implements Runnable {
40+
private final MainActivity mainActivity;
41+
private final JavaEntry entry;
42+
private final int entryIndex;
43+
private final boolean edit;
44+
private final boolean delete;
4545

4646
public UiThreadRunnable(JavaEntry entry, int entryIndex, boolean edit, boolean delete, MainActivity mainActivity) {
4747
this.entry = entry;
@@ -55,7 +55,7 @@ public UiThreadRunnable(JavaEntry entry, int entryIndex, boolean edit, boolean d
5555
public void run() {
5656
ShowEntry se = new ShowEntry(entry, entryIndex, edit, delete);
5757
mainActivity.setBackButtonHandler(se);
58-
mainActivity.getFragmentManager().beginTransaction().replace(R.id.container, se).commitAllowingStateLoss();
58+
mainActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container, se).commitAllowingStateLoss();
5959
InterfaceWithRust.INSTANCE.updateState(se);
6060
}
6161
}

App/src/main/java/org/astonbitecode/rustkeylock/callbacks/ShowMenuCb.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
1616
package org.astonbitecode.rustkeylock.callbacks;
1717

18-
import android.app.Fragment;
18+
import androidx.fragment.app.Fragment;
1919
import android.util.Log;
2020
import org.astonbitecode.rustkeylock.MainActivity;
2121
import org.astonbitecode.rustkeylock.R;
@@ -71,7 +71,7 @@ public void run() {
7171
if (fragment instanceof BackButtonHandler) {
7272
mainActivity.setBackButtonHandler((BackButtonHandler) fragment);
7373
}
74-
mainActivity.getFragmentManager().beginTransaction().replace(R.id.container, fragment)
74+
mainActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment)
7575
.commitAllowingStateLoss();
7676

7777
InterfaceWithRust.INSTANCE.updateState(fragment);

App/src/main/java/org/astonbitecode/rustkeylock/callbacks/ShowMessageCb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public UiThreadRunnable(List<JavaUserOption> optionsList, String message, String
5656
public void run() {
5757
ShowMessage sm = new ShowMessage(severity, message, optionsList);
5858
mainActivity.setBackButtonHandler(sm);
59-
mainActivity.getFragmentManager().beginTransaction().replace(R.id.container, sm).commitAllowingStateLoss();
59+
mainActivity.getSupportFragmentManager().beginTransaction().replace(R.id.container, sm).commitAllowingStateLoss();
6060
}
6161
}
6262

App/src/main/java/org/astonbitecode/rustkeylock/fragments/ChangePassword.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
1616
package org.astonbitecode.rustkeylock.fragments;
1717

18-
import android.app.Fragment;
18+
import androidx.fragment.app.Fragment;
1919
import android.os.Bundle;
2020
import android.util.Log;
2121
import android.view.LayoutInflater;
@@ -44,16 +44,16 @@ public ChangePassword() {
4444
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
4545
View rootView = inflater.inflate(R.layout.fragment_change_password, container, false);
4646

47-
EditText passwordText1 = (EditText) rootView.findViewById(R.id.editPasswordChangePassword1);
47+
EditText passwordText1 = rootView.findViewById(R.id.editPasswordChangePassword1);
4848
this.passwordText1 = passwordText1;
49-
EditText numberText1 = (EditText) rootView.findViewById(R.id.editFavoriteNumberChangePassword1);
49+
EditText numberText1 = rootView.findViewById(R.id.editFavoriteNumberChangePassword1);
5050
this.numberText1 = numberText1;
51-
EditText passwordText2 = (EditText) rootView.findViewById(R.id.editPasswordChangePassword2);
51+
EditText passwordText2 = rootView.findViewById(R.id.editPasswordChangePassword2);
5252
this.passwordText2 = passwordText2;
53-
EditText numberText2 = (EditText) rootView.findViewById(R.id.editFavoriteNumberChangePassword2);
53+
EditText numberText2 = rootView.findViewById(R.id.editFavoriteNumberChangePassword2);
5454
this.numberText2 = numberText2;
5555

56-
Button b = (Button) rootView.findViewById(R.id.buttonApplyChanges);
56+
Button b = rootView.findViewById(R.id.buttonApplyChanges);
5757
b.setOnClickListener(this);
5858

5959
restore(savedInstanceState);

App/src/main/java/org/astonbitecode/rustkeylock/fragments/DirectorySelector.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.astonbitecode.rustkeylock.adapters.DirectoriesAdapter;
2525
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
2626

27-
import android.app.ListFragment;
27+
import androidx.fragment.app.ListFragment;
2828
import android.content.Context;
2929
import android.content.Intent;
3030
import android.os.Bundle;
@@ -39,6 +39,7 @@
3939
import android.widget.ListView;
4040
import android.widget.TextView;
4141
import android.widget.Toast;
42+
import org.jetbrains.annotations.NotNull;
4243

4344
public class DirectorySelector extends ListFragment implements OnClickListener, BackButtonHandler {
4445
private static final long serialVersionUID = 1382314701594691684L;
@@ -51,16 +52,15 @@ public class DirectorySelector extends ListFragment implements OnClickListener,
5152
private TextView currentDirectoryTextView;
5253

5354
public DirectorySelector() {
54-
File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
55-
currentDirectory = downloads;
55+
currentDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
5656
}
5757

5858
@Override
5959
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
6060
View rootView = inflater.inflate(R.layout.fragment_directory_selector, container, false);
61-
Button sdb = (Button) rootView.findViewById(R.id.selectDirectoryButton);
61+
Button sdb = rootView.findViewById(R.id.selectDirectoryButton);
6262
sdb.setOnClickListener(this);
63-
TextView cdtv = (TextView) rootView.findViewById(R.id.directorySelectorCurrent);
63+
TextView cdtv = rootView.findViewById(R.id.directorySelectorCurrent);
6464
currentDirectoryTextView = cdtv;
6565

6666
// Hide the soft keyboard
@@ -75,7 +75,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
7575
public void onActivityCreated(Bundle savedInstanceState) {
7676
super.onActivityCreated(savedInstanceState);
7777
directoriesAdapter = new DirectoriesAdapter(getActivity(), R.layout.directory_element,
78-
new ArrayList<DirectoryEntry>());
78+
new ArrayList<>());
7979
setListAdapter(directoriesAdapter);
8080
currentDirectoryTextView.setText(CURR_DIR_PREFIX + currentDirectory.getAbsolutePath());
8181
applyCurrentDirectory();
@@ -94,7 +94,7 @@ private void applyCurrentDirectory() {
9494
}
9595

9696
@Override
97-
public void onListItemClick(ListView l, View v, int pos, long id) {
97+
public void onListItemClick(@NotNull ListView l, @NotNull View v, int pos, long id) {
9898
Log.d(TAG, "Clicked directory with index " + pos + " in the list of directories");
9999
super.onListItemClick(l, v, pos, id);
100100

App/src/main/java/org/astonbitecode/rustkeylock/fragments/EditConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.astonbitecode.rustkeylock.fragments;
1717

1818
import android.annotation.SuppressLint;
19-
import android.app.Fragment;
19+
import androidx.fragment.app.Fragment;
2020
import android.os.Bundle;
2121
import android.util.Log;
2222
import android.view.LayoutInflater;
@@ -131,7 +131,7 @@ private void prepareUiElements(View v) {
131131
passwordText.setText(strings.get(2));
132132
this.nextcloudPasswordText = passwordText;
133133
CheckBox useSsc = (CheckBox) v.findViewById(R.id.editNextcloudUseSelfSignedCert);
134-
useSsc.setChecked(Boolean.valueOf(strings.get(3)));
134+
useSsc.setChecked(Boolean.parseBoolean(strings.get(3)));
135135
this.useSelfSignedCert = useSsc;
136136

137137
TextView dbxTokenLabel = (TextView) v.findViewById(R.id.editConfigurationTokenLabel);

0 commit comments

Comments
 (0)