-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from wanam/add_prefs
Add prefs UI to make some features optional
- Loading branch information
Showing
17 changed files
with
260 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
app/src/main/java/ma/wanam/youtubeadaway/MainActivity.java
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
app/src/main/java/ma/wanam/youtubeadaway/SettingsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package ma.wanam.youtubeadaway; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import androidx.appcompat.app.ActionBar; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.preference.Preference; | ||
import androidx.preference.PreferenceFragmentCompat; | ||
|
||
public class SettingsActivity extends AppCompatActivity { | ||
private static SharedPreferences prefs; | ||
|
||
@SuppressLint("WorldReadableFiles") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.settings_activity); | ||
if (savedInstanceState == null) { | ||
getSupportFragmentManager() | ||
.beginTransaction() | ||
.replace(R.id.settings, new SettingsFragment()) | ||
.commit(); | ||
} | ||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
} | ||
try { | ||
prefs = getSharedPreferences(getPackageName() + "_preferences", MODE_WORLD_READABLE); | ||
} catch (SecurityException ignored) { | ||
Log.e(getPackageName(), ignored.toString()); | ||
} | ||
} | ||
|
||
public static class SettingsFragment extends PreferenceFragmentCompat { | ||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
setPreferencesFromResource(R.xml.root_preferences, rootKey); | ||
|
||
// copy btc wallet address to the clipboard | ||
getPreferenceScreen().findPreference("donate_btc") | ||
.setOnPreferenceClickListener(preference -> { | ||
ClipboardManager clipboardManager = (ClipboardManager) | ||
getActivity().getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData clipData = ClipData.newPlainText(preference.getKey(), preference.getSummary()); | ||
clipboardManager.setPrimaryClip(clipData); | ||
|
||
return true; | ||
}); | ||
|
||
// set module status | ||
Preference statusPreference = getPreferenceScreen().findPreference("status"); | ||
statusPreference.setIcon(XChecker.isEnabled() ? android.R.drawable.ic_dialog_info : android.R.drawable.ic_dialog_alert); | ||
statusPreference.setSummary(XChecker.isEnabled() ? R.string.module_active : R.string.module_inactive); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.