Skip to content

Commit

Permalink
finally updating Settings/Preferences to not be deprecated and use an…
Browse files Browse the repository at this point in the history
…droidx.preference package
  • Loading branch information
n8fr8 committed Apr 7, 2023
1 parent e5a3d01 commit 983df87
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app-tv/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</activity> <!-- This is for ensuring the background service still runs when/if the app is swiped away -->

<activity
android:name="org.torproject.android.core.ui.SettingsPreferencesActivity"
android:name="org.torproject.android.core.ui.SettingsPreferencesFragment"
android:label="@string/app_name" />
<activity
android:name=".ui.AppManagerActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.torproject.android.core.Languages;
import org.torproject.android.core.LocaleHelper;
import org.torproject.android.core.ui.Rotate3dAnimation;
import org.torproject.android.core.ui.SettingsPreferencesActivity;
import org.torproject.android.core.ui.SettingsPreferencesFragment;
import org.torproject.android.tv.ui.AppConfigActivity;
import org.torproject.android.tv.ui.AppManagerActivity;
import org.torproject.android.tv.ui.onboarding.OnboardingActivity;
Expand Down Expand Up @@ -405,7 +405,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_newnym) {
requestNewTorIdentity();
} else if (item.getItemId() == R.id.menu_settings) {
Intent intent = SettingsPreferencesActivity.createIntent(this, R.xml.preferences);
Intent intent = SettingsPreferencesFragment.createIntent(this, R.xml.preferences);
startActivityForResult(intent, REQUEST_SETTINGS);
}
else if (item.getItemId() == R.id.menu_about) {
Expand Down
8 changes: 6 additions & 2 deletions app-tv/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="@string/pref_general_group">
<PreferenceCategory android:title="@string/pref_general_group"
android:iconSpaceReserved="false"
>
<ListPreference
android:key="pref_default_locale"
android:title="@string/set_locale_title"
android:enabled="true"
android:selectable="true" />
android:selectable="true"

/>

<CheckBoxPreference
android:defaultValue="true"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</activity>

<activity
android:name=".core.ui.SettingsPreferencesActivity"
android:name=".core.ui.SettingsPreferencesFragment"
android:theme="@style/OrbotActivityTheme" />

<activity
Expand Down
Binary file modified app/src/main/ic_launcher-playstore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions app/src/main/java/org/torproject/android/MoreFragment.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.torproject.android

import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -13,7 +11,8 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import org.torproject.android.OrbotActivity.Companion.REQUEST_CODE_SETTINGS
import org.torproject.android.OrbotActivity.Companion.REQUEST_VPN_APP_SELECT
import org.torproject.android.core.ui.SettingsPreferencesActivity
import org.torproject.android.core.ui.SettingsActivity
import org.torproject.android.core.ui.SettingsPreferencesFragment
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.OrbotService
import org.torproject.android.ui.*
Expand Down Expand Up @@ -65,7 +64,9 @@ class MoreFragment : Fragment() {
activity?.startActivityForResult(Intent(requireActivity(), AppManagerActivity::class.java), REQUEST_VPN_APP_SELECT)
},
OrbotMenuAction(R.string.menu_settings, R.drawable.ic_settings_gear) {
activity?.startActivityForResult(SettingsPreferencesActivity.createIntent(requireActivity(), R.xml.preferences), REQUEST_CODE_SETTINGS)

// activity?.startActivityForResult(SettingsPreferencesFragment.createIntent(requireActivity(), R.xml.preferences), REQUEST_CODE_SETTINGS)
activity?.startActivityForResult(Intent(context, SettingsActivity::class.java), REQUEST_CODE_SETTINGS)
},
OrbotMenuAction(R.string.menu_log, R.drawable.ic_log) { showLog()},
OrbotMenuAction(R.string.menu_about, R.drawable.ic_about) { AboutDialogFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected void onCreate(Bundle savedInstanceState) {
listAppsAll = findViewById(R.id.applistview);
progressBar = findViewById(R.id.progressBar);

//need a better way to manage this list
alSuggested = new ArrayList<>();
alSuggested.add("org.thoughtcrime.securesms");
alSuggested.add("com.whatsapp");
Expand All @@ -86,6 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {
alSuggested.add("com.facebook.orca");
alSuggested.add("com.facebook.mlite");
alSuggested.add("com.brave.browser");
alSuggested.add("org.mozilla.focus");

}

Expand All @@ -110,7 +112,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_refresh_apps) {
mApps = null;
reloadApps();
} else if (item.getItemId() == android.R.id.home) {
}
else if (item.getItemId() == R.id.menu_save_apps) {
saveAppSettings();
finish();
}
else if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
Expand Down Expand Up @@ -405,7 +412,6 @@ else if (v.getTag() instanceof ListEntry)
cbox.setChecked(app.isTorified());
}

saveAppSettings();
}
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/app_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
xmlns:yourapp="http://schemas.android.com/apk/res-auto"
>

<item android:id="@+id/menu_save_apps"
android:title="@string/save"
android:icon="@drawable/ic_green_check"
yourapp:showAsAction="always|withText"
/>

<item android:id="@+id/menu_refresh_apps"
android:title="@string/refresh_apps"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
<color name="ic_launcher_background">#7126C8</color>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,6 @@
<string name="menu_more">More</string>
<string name="option_only_on_wifi">Only on Wifi</string>
<string name="option_only_when_charging">Only when charging</string>
<string name="setting_padding">Padding</string>
<string name="setting_debug">Debug</string>
</resources>
56 changes: 45 additions & 11 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:iconSpaceReserved="false"

<PreferenceCategory android:title="@string/pref_general_group">
>

<PreferenceCategory android:title="@string/pref_general_group"
app:iconSpaceReserved="false"

>
<ListPreference
android:key="pref_default_locale"
android:title="@string/set_locale_title"
android:enabled="true"
android:selectable="true" />
android:selectable="true"

/>

<CheckBoxPreference
android:defaultValue="true"
Expand Down Expand Up @@ -37,7 +46,10 @@

<PreferenceCategory
android:summary="@string/pref_node_configuration_summary"
android:title="@string/pref_node_configuration">
android:title="@string/pref_node_configuration"

app:iconSpaceReserved="false"
>

<EditTextPreference
android:dialogTitle="@string/pref_entrance_node_dialog"
Expand All @@ -63,7 +75,10 @@

</PreferenceCategory>

<PreferenceCategory android:title="@string/relays">
<PreferenceCategory android:title="@string/relays"

app:iconSpaceReserved="false"
>
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
Expand All @@ -88,7 +103,10 @@

</PreferenceCategory>

<PreferenceCategory android:title="@string/reachable_addresses">
<PreferenceCategory android:title="@string/reachable_addresses"

app:iconSpaceReserved="false"
>
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
Expand All @@ -104,7 +122,10 @@
android:title="@string/reachable_ports" />
</PreferenceCategory>

<PreferenceCategory android:title="Connectivity">
<PreferenceCategory android:title="Connectivity"

app:iconSpaceReserved="false"
>
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
Expand Down Expand Up @@ -137,7 +158,11 @@
android:title="@string/pref_disable_ipv4" />
</PreferenceCategory>

<PreferenceCategory android:title="Padding">
<PreferenceCategory android:title="@string/setting_padding"


app:iconSpaceReserved="false"
>
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
Expand All @@ -164,7 +189,10 @@
android:title="@string/pref_reduced_circuit_padding" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_proxy_title">
<PreferenceCategory android:title="@string/pref_proxy_title"

app:iconSpaceReserved="false"
>
<EditTextPreference
android:dialogTitle="@string/pref_proxy_type_dialog"
android:key="pref_proxy_type"
Expand Down Expand Up @@ -195,7 +223,10 @@
android:title="@string/pref_proxy_password_title" />
</PreferenceCategory>

<PreferenceCategory android:title="Debug">
<PreferenceCategory android:title="@string/setting_debug"

app:iconSpaceReserved="false"
>

<EditTextPreference
android:inputType="number"
Expand Down Expand Up @@ -251,7 +282,10 @@
android:title="@string/pref_disable_network_title" />

</PreferenceCategory>
<PreferenceCategory android:title="@string/snowflake_proxy_pref_category">
<PreferenceCategory android:title="@string/snowflake_proxy_pref_category"

app:iconSpaceReserved="false"
>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_be_a_snowflake"
Expand Down
5 changes: 4 additions & 1 deletion appcore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ dependencies {
implementation(
project(':orbotservice'),
"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version",
libs.androidx_appcompat
libs.androidx_appcompat,
"androidx.preference:preference:1.1.0"
)
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
11 changes: 11 additions & 0 deletions appcore/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application>
<activity
android:name=".ui.SettingsActivity"
android:exported="false"
android:theme="@style/Theme.AppCompat"
>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.torproject.android.core.ui

import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import org.torproject.android.core.R

class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)


supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportFragmentManager
.beginTransaction()
.replace(android.R.id.content, SettingsPreferencesFragment())
.commit()

}


override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
return super.onOptionsItemSelected(item)
}
}

0 comments on commit 983df87

Please sign in to comment.