Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ public void onClick(View v) {
onSdCardNotMounted();
} else if (!CollectionHelper.isCurrentAnkiDroidDirAccessible(this)) {
// AnkiDroid directory inaccessible
Intent prefIntent = CompatHelper.getCompat().getAdvancedPreferencesIntent(this);
startActivityForResultWithoutAnimation(prefIntent, REQUEST_PATH_UPDATE);
Intent i = CompatHelper.getCompat().getPreferenceSubscreenIntent(this, "com.ichi2.anki.prefs.advanced");
startActivityForResultWithoutAnimation(i, REQUEST_PATH_UPDATE);
Toast.makeText(this, R.string.directory_inaccessible, Toast.LENGTH_LONG).show();
} else {
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_LOAD_FAILED);
Expand Down
24 changes: 23 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ protected void onResume() {
// syncAccount's summary can change while preferences are still open (user logs
// in from preferences screen), so we need to update it here.
updatePreference(prefs, "syncAccount", this);
updatePreference(prefs, "custom_sync_server_link", this);
}
}

Expand Down Expand Up @@ -282,6 +283,16 @@ public boolean onPreferenceChange(Preference preference, final Object newValue)
}
}
});
// Custom sync server option
Preference customSyncServerPreference = screen.findPreference("custom_sync_server_link");
customSyncServerPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent i = CompatHelper.getCompat().getPreferenceSubscreenIntent(Preferences.this,
"com.ichi2.anki.prefs.custom_sync_server");
startActivity(i);
return true;
}
});
// Force full sync option
Preference fullSyncPreference = screen.findPreference("force_full_sync");
fullSyncPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
Expand All @@ -296,6 +307,10 @@ public boolean onPreferenceClick(Preference preference) {
// Workaround preferences
removeUnnecessaryAdvancedPrefs(screen);
break;
case "com.ichi2.anki.prefs.custom_sync_server":
getSupportActionBar().setTitle(R.string.custom_sync_server_title);
listener.addPreferencesFromResource(R.xml.preferences_custom_sync_server);
break;
}
}

Expand Down Expand Up @@ -374,7 +389,6 @@ private void initPreference(Preference pref) {
CharSequence s = pref.getSummary();
mOriginalSumarries.put(pref.getKey(), (s != null) ? s.toString() : "");
// Update summary

updateSummary(pref);
}

Expand Down Expand Up @@ -515,8 +529,15 @@ private void updateSummary(Preference pref) {
if (pref == null || pref.getKey() == null) {
return;
}
// Handle special cases
if (pref.getKey().equals("about_dialog_preference")) {
pref.setSummary(getResources().getString(R.string.about_version) + " " + VersionUtils.getPkgVersionName());
} else if (pref.getKey().equals("custom_sync_server_link")) {
if (!AnkiDroidApp.getSharedPrefs(this).getBoolean("useCustomSyncServer", false)) {
pref.setSummary(R.string.disabled);
} else {
pref.setSummary(AnkiDroidApp.getSharedPrefs(this).getString("syncBaseUrl", ""));
}
}
// Get value text
String value;
Expand Down Expand Up @@ -709,6 +730,7 @@ public void onResume() {
// syncAccount's summary can change while preferences are still open (user logs
// in from preferences screen), so we need to update it here.
((Preferences) getActivity()).updatePreference(prefs, "syncAccount", this);
((Preferences) getActivity()).updatePreference(prefs, "custom_sync_server_link", this);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/compat/Compat.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public interface Compat {
void setSelectableBackground(View view);
void openUrl(AnkiActivity activity, Uri uri);
void supportAddContentMenu(final DeckPicker a);
Intent getAdvancedPreferencesIntent(Context context);
Intent getPreferenceSubscreenIntent(Context context, String subscreen);
}

4 changes: 2 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/compat/CompatV10.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ public void onClick(@NonNull MaterialDialog d, @NonNull DialogAction w) {
}

@Override
public Intent getAdvancedPreferencesIntent(Context context) {
public Intent getPreferenceSubscreenIntent(Context context, String subscreen) {
// We're using "legacy preference headers" below API 11
Intent i = new Intent(context, Preferences.class);
i.setAction("com.ichi2.anki.prefs.advanced");
i.setAction(subscreen);
return i;
}
}
5 changes: 3 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/compat/CompatV11.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public void disableDatabaseWriteAheadLogging(SQLiteDatabase db) {
}

@Override
public Intent getAdvancedPreferencesIntent(Context context) {
public Intent getPreferenceSubscreenIntent(Context context, String subscreen) {
Intent i = new Intent(context, Preferences.class);
i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, "com.ichi2.anki.Preferences$SettingsFragment");
Bundle extras = new Bundle();
extras.putString("subscreen", "com.ichi2.anki.prefs.advanced");
extras.putString("subscreen", subscreen);
i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, extras);
i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
return i;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.ichi2.libanki.sync;

import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabaseCorruptException;


import com.ichi2.anki.AnkiDatabaseManager;
import com.ichi2.anki.AnkiDb;
import com.ichi2.anki.AnkiDroidApp;
import com.ichi2.anki.R;
import com.ichi2.anki.exception.UnknownHttpResponseException;
import com.ichi2.async.Connection;
Expand Down Expand Up @@ -60,6 +62,13 @@ public FullSyncer(Collection col, String hkey, Connection con) {

@Override
public String syncURL() {
// Allow user to specify custom sync server
SharedPreferences userPreferences = AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance());
if (userPreferences!= null && userPreferences.getBoolean("useCustomSyncServer", false)) {
File syncBase = new File(userPreferences.getString("syncBaseUrl", Consts.SYNC_BASE));
return new File(syncBase, "/sync").toString() + "/";
}
// Usual case
return Consts.SYNC_BASE + "sync/";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@



import android.content.SharedPreferences;

import com.ichi2.anki.AnkiDroidApp;
import com.ichi2.anki.exception.UnknownHttpResponseException;
import com.ichi2.async.Connection;
Expand Down Expand Up @@ -448,6 +450,13 @@ public HttpResponse register(String user, String pw) throws UnknownHttpResponseE


public String syncURL() {
// Allow user to specify custom sync server
SharedPreferences userPreferences = AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance());
if (userPreferences!= null && userPreferences.getBoolean("useCustomSyncServer", false)) {
File syncBase = new File(userPreferences.getString("syncBaseUrl", Consts.SYNC_BASE));
return new File(syncBase, "/sync").toString() + "/";
}
// Usual case
return Consts.SYNC_BASE + "sync/";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package com.ichi2.libanki.sync;

import android.content.SharedPreferences;
import android.text.TextUtils;

import com.ichi2.anki.AnkiDroidApp;
import com.ichi2.anki.exception.MediaSyncException;
import com.ichi2.anki.exception.UnknownHttpResponseException;
import com.ichi2.async.Connection;
Expand Down Expand Up @@ -55,6 +57,13 @@ public RemoteMediaServer(Collection col, String hkey, Connection con) {

@Override
public String syncURL() {
// Allow user to specify custom sync server
SharedPreferences userPreferences = AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance());
if (userPreferences!= null && userPreferences.getBoolean("useCustomSyncServer", false)) {
File mediaSyncBase = new File(userPreferences.getString("syncMediaUrl", Consts.SYNC_MEDIA_BASE));
return mediaSyncBase.toString() + "/";
}
// Usual case
return Consts.SYNC_MEDIA_BASE;
}

Expand Down
11 changes: 9 additions & 2 deletions AnkiDroid/src/main/res/layout/my_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,15 @@
android:text="@string/sign_up_description"
android:layout_gravity="center"
android:textSize="@dimen/abc_text_size_button_material"
android:textStyle="bold"
/>
android:textStyle="bold"/>
<TextView
android:id="@+id/no_account_not_affiliated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_up_not_affiliated"
android:layout_gravity="center"
android:textSize="@dimen/abc_text_size_button_material"
android:textStyle="italic"/>

<Button
android:id="@+id/sign_up_button"
Expand Down
3 changes: 2 additions & 1 deletion AnkiDroid/src/main/res/values/04-network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<string name="menu_get_shared_decks">Get shared decks</string>
<string name="connection_error_message">A network error has occurred</string>
<string name="not_logged_in_title">Log in to AnkiWeb</string>
<string name="login_create_account_message">You must log in to an AnkiWeb account. You can create one in the next step.</string>
<string name="login_create_account_message">You must log in to a third party account to use the cloud sync service. You can create one in the next step.</string>
<string name="no_email_client">No email client available</string>

<!-- MyAccount.java -->
Expand All @@ -41,6 +41,7 @@
<string name="password_repeat">Repeat password</string>
<string name="log_in">Log in</string>
<string name="sign_up_description">Don’t have an AnkiWeb account? It’s free!</string>
<string name="sign_up_not_affiliated">Note: AnkiWeb is not affiliated with AnkiDroid</string>
<string name="sign_up">Sign up</string>
<string name="logged_as">Logged in as</string>
<string name="log_out">Log out</string>
Expand Down
9 changes: 8 additions & 1 deletion AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <http://www.gnu.org/licenses/>.
--><resources>

<!-- generic strings -->
<string name="disabled">Disabled</string>
<!-- preferences.xml categories-->
<string name="pref_cat_general">AnkiDroid</string>
<string name="pref_cat_general_summ">General settings</string>
Expand Down Expand Up @@ -139,6 +140,12 @@
<string name="convert_fen_text_summ">Draw chessboard from Forsyth–Edwards Notation. The notation must be enclosed in [fen][/fen] tags.</string>
<string name="enable_api_title">Enable AnkiDroid API</string>
<string name="enable_api_summary">Let other apps connect to AnkiDroid and read / write data without your intervention</string>
<!-- Custom sync server settings -->
<string name="custom_sync_server_title">Custom sync server</string>
<string name="custom_sync_server_enable_title">Use custom sync server</string>
<string name="custom_sync_server_enable_summary">If you don\'t want to use the proprietary AnkiWeb service you can specify an alternative server here</string>
<string name="custom_sync_server_base_url_title">Sync url</string>
<string name="custom_sync_server_media_url_title">Media sync url</string>

<!-- studyoptions -->
<string name="studyoptions_limit_select_tags">Select tags</string>
Expand Down
3 changes: 3 additions & 0 deletions AnkiDroid/src/main/res/xml/preferences_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
android:key="force_full_sync"
android:title="@string/force_full_sync_title"
android:summary="@string/force_full_sync_summary" />
<Preference
android:key="custom_sync_server_link"
android:title="@string/custom_sync_server_title"/>
<PreferenceCategory android:title="@string/pref_cat_performance" >
<com.ichi2.ui.SeekBarPreference
android:defaultValue="8"
Expand Down
21 changes: 21 additions & 0 deletions AnkiDroid/src/main/res/xml/preferences_custom_sync_server.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>


<!-- Advanced Preferences -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="useCustomSyncServer"
android:title="Use custom sync server"
android:summary="@string/custom_sync_server_enable_summary"
android:defaultValue="false"/>
<EditTextPreference
android:key="syncBaseUrl"
android:dependency="useCustomSyncServer"
android:title="@string/custom_sync_server_base_url_title"
android:defaultValue="https://ankiweb.net/"/>
<EditTextPreference
android:key="syncMediaUrl"
android:dependency="useCustomSyncServer"
android:title="@string/custom_sync_server_media_url_title"
android:defaultValue="https://msync.ankiweb.net/"/>
</PreferenceScreen>