diff --git a/app/src/main/assets/dark.css b/app/src/main/assets/dark.css index 37cf94769..2790017f5 100755 --- a/app/src/main/assets/dark.css +++ b/app/src/main/assets/dark.css @@ -28,22 +28,6 @@ body { font-family: serif; } -.font-size-75 { - font-size: 75%; -} - -.font-size-125 { - font-size: 125%; -} - -.font-size-150 { - font-size: 150%; -} - -.font-size-175 { - font-size: 175%; -} - /* ========================================================================== 1 = Style Guide ========================================================================== */ diff --git a/app/src/main/assets/main.css b/app/src/main/assets/main.css index f9a9262c4..cc7a3421a 100755 --- a/app/src/main/assets/main.css +++ b/app/src/main/assets/main.css @@ -27,22 +27,6 @@ body { font-family: serif; } -.font-size-75 { - font-size: 75%; -} - -.font-size-125 { - font-size: 125%; -} - -.font-size-150 { - font-size: 150%; -} - -.font-size-175 { - font-size: 175%; -} - /* ========================================================================== 1 = Style Guide ========================================================================== */ diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java b/app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java index 0096c76c2..fc58121ed 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java @@ -62,16 +62,4 @@ public boolean getBoolean(String key, boolean defValue) { return pref.getBoolean(key, defValue); } - // well, that's embarrassingly blunt, but I'm too lazy to make it any better right now - // TODO: rewrite whole font size thing - public String getFontSizeCssClass() { - switch(getInt(FONT_SIZE, -1)) { - case 0: return "font-size-75"; - case 2: return "font-size-125"; - case 3: return "font-size-150"; - case 4: return "font-size-175"; - default: return null; - } - } - } diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/BaseActionBarActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/BaseActionBarActivity.java index dc565f7ec..06d5a5cfb 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/BaseActionBarActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/BaseActionBarActivity.java @@ -9,22 +9,22 @@ public class BaseActionBarActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addBackButtonToActionBar(); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addBackButtonToActionBar(); + } - @TargetApi(11) - protected void addBackButtonToActionBar() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - try { - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - } catch (Exception e) { - // - } - } - } + @TargetApi(11) + protected void addBackButtonToActionBar() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + try { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } catch (Exception e) { + // + } + } + } @TargetApi(11) protected void hideBackButtonToActionBar() { @@ -38,11 +38,11 @@ protected void hideBackButtonToActionBar() { } @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - this.finish(); - return true; - } - return super.onOptionsItemSelected(item); - } + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + this.finish(); + return true; + } + return super.onOptionsItemSelected(item); + } } diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java index 2303b259c..277bc97d9 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java @@ -17,6 +17,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; +import android.webkit.ConsoleMessage; import android.webkit.HttpAuthHandler; import android.webkit.WebChromeClient; import android.webkit.WebView; @@ -28,6 +29,9 @@ import android.widget.TextView; import android.widget.Toast; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -47,14 +51,14 @@ public class ReadArticleActivity extends BaseActionBarActivity { - public static final String EXTRA_ID = "ReadArticleActivity.id"; - public static final String EXTRA_LIST_ARCHIVED = "ReadArticleActivity.archived"; - public static final String EXTRA_LIST_FAVORITES = "ReadArticleActivity.favorites"; + public static final String EXTRA_ID = "ReadArticleActivity.id"; + public static final String EXTRA_LIST_ARCHIVED = "ReadArticleActivity.archived"; + public static final String EXTRA_LIST_FAVORITES = "ReadArticleActivity.favorites"; private static final String TAG = ReadArticleActivity.class.getSimpleName(); private ScrollView scrollView; - private WebView webViewContent; + private WebView webViewContent; private TextView loadingPlaceholder; private LinearLayout bottomTools; private View hrBar; @@ -69,6 +73,8 @@ public class ReadArticleActivity extends BaseActionBarActivity { private String originalUrlText; private String domainText; private Double positionToRestore; + private int webViewHeightBeforeUpdate; + private Runnable positionRestorationRunnable; private Long previousArticleID; private Long nextArticleID; @@ -77,12 +83,14 @@ public class ReadArticleActivity extends BaseActionBarActivity { private Settings settings; + private int fontSize = 100; + public void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.article); + super.onCreate(savedInstanceState); + setContentView(R.layout.article); - Intent intent = getIntent(); + Intent intent = getIntent(); long articleId = intent.getLongExtra(EXTRA_ID, -1); if(intent.hasExtra(EXTRA_LIST_FAVORITES)) { contextFavorites = intent.getBooleanExtra(EXTRA_LIST_FAVORITES, false); @@ -98,7 +106,7 @@ public void onCreate(Bundle savedInstanceState) { titleText = mArticle.getTitle(); originalUrlText = mArticle.getUrl(); - String htmlContent = mArticle.getContent(); + String htmlContent = mArticle.getContent(); positionToRestore = mArticle.getArticleProgress(); setTitle(titleText); @@ -122,11 +130,14 @@ public void onCreate(Bundle savedInstanceState) { break; } - List additionalClasses = new ArrayList<>(2); + fontSize = settings.getInt(Settings.FONT_SIZE, fontSize); + boolean serifFont = settings.getBoolean(Settings.SERIF_FONT, false); + + if(fontSize < 5) fontSize = 100; // TODO: remove: temp hack for compatibility + + List additionalClasses = new ArrayList<>(1); if(highContrast) additionalClasses.add("high-contrast"); - if(settings.getBoolean(Settings.SERIF_FONT, false)) additionalClasses.add("serif-font"); - String fontSizeCssClass = settings.getFontSizeCssClass(); - if(fontSizeCssClass != null) additionalClasses.add(fontSizeCssClass); + if(serifFont) additionalClasses.add("serif-font"); String classAttr; if(!additionalClasses.isEmpty()) { @@ -148,42 +159,33 @@ public void onCreate(Bundle savedInstanceState) { domainText = url.getHost(); } catch (Exception ignored) {} - String htmlHeader = "\n" + - "\t\n" + - "\t\t\n" + - "\t\t\n" + - "\t\t\n" + - "\t\t\n" + - "\t\n" + - "\t\t
\n" + - "\t\t\t\n" + - "\t\t\t\t
\n" + - "\t\t\t\t\t
\n" + - "\t\t\t\t\t\t
\n" + - "\t\t\t\t\t\t\t

" + titleText + "

\n" + - "\t\t\t\t\t\t\t\n" + - "\t\t\t\t\t\t\t" + domainText + "\n" + - "\t\t\t\t\t\t
\n" + - "\t\t\t\t\t\t
"; - - String htmlFooter = "
\n" + - "\t\t\t\t\t
\n" + - "\t\t\t\t
\n" + - "\t\t\t\n" + - "\t\t
\n" + - ""; + String htmlBase; + try { + htmlBase = readRawString(R.raw.webview_htmlbase); + } catch(Exception ignored) { + // TODO: show error message + finish(); + return; + } + + String htmlPage = String.format(htmlBase, cssName, classAttr, titleText, + originalUrlText, domainText, htmlContent); final String httpAuthHost = settings.getUrl(); final String httpAuthUsername = settings.getString(Settings.HTTP_AUTH_USERNAME, null); final String httpAuthPassword = settings.getString(Settings.HTTP_AUTH_PASSWORD, null); scrollView = (ScrollView) findViewById(R.id.scroll); - webViewContent = (WebView) findViewById(R.id.webViewContent); + webViewContent = (WebView) findViewById(R.id.webViewContent); webViewContent.getSettings().setJavaScriptEnabled(true); // TODO: make optional? - webViewContent.setWebChromeClient(new WebChromeClient() {}); // TODO: check - webViewContent.loadDataWithBaseURL("file:///android_asset/", - htmlHeader + htmlContent + htmlFooter, "text/html", "utf-8", null); - + webViewContent.setWebChromeClient(new WebChromeClient() { + @Override + public boolean onConsoleMessage(ConsoleMessage cm) { + Log.d("WebView.onCM", String.format("%s @ %d: %s", cm.message(), + cm.lineNumber(), cm.sourceId())); + return true; + } + }); webViewContent.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { @@ -226,6 +228,9 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, } }); + webViewContent.loadDataWithBaseURL("file:///android_asset/", htmlPage, + "text/html", "utf-8", null); + // TODO: remove logging after calibrated GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() { @@ -290,13 +295,13 @@ public boolean onTouch(View v, MotionEvent event) { if(mArticle.getArchive()) { btnMarkRead.setText(R.string.btnMarkUnread); } - btnMarkRead.setOnClickListener(new OnClickListener() { + btnMarkRead.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - markAsReadAndClose(); - } - }); + @Override + public void onClick(View v) { + markAsReadAndClose(); + } + }); ImageButton btnGoPrevious; ImageButton btnGoNext; @@ -320,7 +325,7 @@ public void onClick(View v) { openNextArticle(); } }); - } + } private void loadingFinished() { loadingFinished = true; @@ -329,7 +334,24 @@ private void loadingFinished() { bottomTools.setVisibility(View.VISIBLE); hrBar.setVisibility(View.VISIBLE); - restoreReadingPosition(); + if(applyDisplaySettings()) { + restorePositionAfterUpdate(); + } else { + restoreReadingPosition(); + } + } + + private boolean applyDisplaySettings() { + prepareToRestorePosition(false); + + boolean changed = false; + + if(fontSize != 100) { + changed = true; + setFontSize(webViewContent, fontSize); + } + + return changed; } private boolean openUrl(final String url) { @@ -485,6 +507,12 @@ public boolean onOptionsItemSelected(MenuItem item) { return deleteArticle(); case R.id.menuOpenOriginal: return openOriginal(); + case R.id.menuIncreaseFontSize: + changeFontSize(true); + return true; + case R.id.menuDecreaseFontSize: + changeFontSize(false); + return true; default: return super.onOptionsItemSelected(item); } @@ -559,6 +587,95 @@ private Long getAdjacentArticle(boolean previous) { return null; } + private String readRawString(int id) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(id))); + + StringBuilder sb = new StringBuilder(); + String s; + while((s = reader.readLine()) != null) { + sb.append(s).append('\n'); + } + + return sb.toString(); + } finally { + if(reader != null) { + reader.close(); + } + } + } + + private void prepareToRestorePosition(boolean savePosition) { + if(savePosition) positionToRestore = getReadingPosition(); + + webViewHeightBeforeUpdate = webViewContent.getHeight(); + } + + private void restorePositionAfterUpdate() { + cancelPositionRestoration(); + + webViewContent.postDelayed(positionRestorationRunnable = new Runnable() { + int counter; + + @Override + public void run() { + if(webViewContent.getHeight() == webViewHeightBeforeUpdate) { + if(++counter > 1000) { + Log.d(TAG, "restorePositionAfterUpdate() giving up"); + return; + } + + Log.v(TAG, "restorePositionAfterUpdate() scheduling another postDelay"); + webViewContent.postDelayed(this, 10); + } else { + Log.d(TAG, "restorePositionAfterUpdate() restoring position"); + restoreReadingPosition(); + } + } + }, 10); + } + + private void cancelPositionRestoration() { + if(positionRestorationRunnable != null) { + Log.d(TAG, "cancelPositionRestoration() trying to cancel previous task"); + webViewContent.removeCallbacks(positionRestorationRunnable); + positionRestorationRunnable = null; + } + } + + private void changeFontSize(boolean increase) { + prepareToRestorePosition(true); + + int step = 5; + fontSize += step * (increase ? 1 : -1); + if(!increase && fontSize < 5) fontSize = 5; + + setFontSize(webViewContent, fontSize); + + settings.setInt(Settings.FONT_SIZE, fontSize); + + restorePositionAfterUpdate(); + } + + private void setFontSize(WebView view, int size) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + setFontSizeNew(view, size); + } else { + setFontSizeOld(view, size); + } + } + + @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) + private void setFontSizeNew(WebView view, int size) { + view.getSettings().setTextZoom(size); + } + + @TargetApi(Build.VERSION_CODES.FROYO) + private void setFontSizeOld(WebView view, int size) { + view.getSettings().setDefaultFontSize(size); + } + private Drawable getIcon(int id, Resources.Theme theme) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return getIconNew(id, theme); diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/SettingsActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/SettingsActivity.java index 4a10667ed..d44609634 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/SettingsActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/SettingsActivity.java @@ -32,163 +32,163 @@ import fr.gaulupeau.apps.Poche.network.tasks.TestConnectionTask; public class SettingsActivity extends BaseActionBarActivity { - Button btnTestConnection; - Button btnGetCredentials; - Button btnDone; - EditText editPocheUrl; - EditText editAPIUsername; - EditText editAPIToken; - CheckBox allCerts; - AppCompatSpinner themeChooser; - AppCompatSpinner fontSizeChooser; - CheckBox serifFont; - EditText listLimit; - TextView textViewVersion; - EditText username; - EditText password; - EditText httpAuthUsername; - EditText httpAuthPassword; - ProgressDialog progressDialog; + Button btnTestConnection; + Button btnGetCredentials; + Button btnDone; + EditText editPocheUrl; + EditText editAPIUsername; + EditText editAPIToken; + CheckBox allCerts; + AppCompatSpinner themeChooser; + EditText fontSizeET; + CheckBox serifFont; + EditText listLimit; + TextView textViewVersion; + EditText username; + EditText password; + EditText httpAuthUsername; + EditText httpAuthPassword; + ProgressDialog progressDialog; private Settings settings; - private WallabagSettings wallabagSettings; + private WallabagSettings wallabagSettings; - private TestConnectionTask testConnectionTask; - private GetCredentialsTask getCredentialsTask; + private TestConnectionTask testConnectionTask; + private GetCredentialsTask getCredentialsTask; @Override - protected void onCreate(Bundle savedInstanceState) { - Themes.applyTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.settings); - - settings = App.getInstance().getSettings(); - wallabagSettings = WallabagSettings.settingsFromDisk(settings); - - if (!wallabagSettings.isValid()) { - hideBackButtonToActionBar(); - } - - editPocheUrl = (EditText) findViewById(R.id.pocheUrl); - editAPIUsername = (EditText) findViewById(R.id.APIUsername); - editAPIToken = (EditText) findViewById(R.id.APIToken); - allCerts = (CheckBox) findViewById(R.id.accept_all_certs_cb); - themeChooser = (AppCompatSpinner) findViewById(R.id.themeChooser); - fontSizeChooser = (AppCompatSpinner) findViewById(R.id.fontSizeChooser); - serifFont = (CheckBox) findViewById(R.id.ui_font_serif); - listLimit = (EditText) findViewById(R.id.list_limit_number); - - editPocheUrl.setText(wallabagSettings.wallabagURL); - editPocheUrl.setSelection(editPocheUrl.getText().length()); - editAPIUsername.setText(wallabagSettings.userID); - editAPIToken.setText(wallabagSettings.userToken); - allCerts.setChecked(settings.getBoolean(Settings.ALL_CERTS, false)); - - Themes.Theme[] themes = Themes.Theme.values(); - String[] themeOptions = new String[themes.length]; - Themes.Theme currentThemeName = Themes.getCurrentTheme(); - int currentThemeIndex = 0; - for(int i = 0; i < themes.length; i++) { - if(themes[i] == currentThemeName) currentThemeIndex = i; - themeOptions[i] = getString(themes[i].getNameId()); - } - themeChooser.setAdapter(new ArrayAdapter<>( - this, android.R.layout.simple_spinner_item, themeOptions)); - themeChooser.setSelection(currentThemeIndex); - - fontSizeChooser.setAdapter(ArrayAdapter.createFromResource(this, - R.array.settings_ui_fontSizeOptions, android.R.layout.simple_spinner_item)); - fontSizeChooser.setSelection(settings.getInt(Settings.FONT_SIZE, 1)); // TODO: fix default value - - serifFont.setChecked(settings.getBoolean(Settings.SERIF_FONT, false)); - listLimit.setText(String.valueOf(settings.getInt(Settings.LIST_LIMIT, 50))); - - username = (EditText) findViewById(R.id.username); - username.setText(settings.getKey(Settings.USERNAME)); - password = (EditText) findViewById(R.id.password); - password.setText(settings.getKey(Settings.PASSWORD)); - - httpAuthUsername = (EditText) findViewById(R.id.http_auth_username); - httpAuthUsername.setText(settings.getKey(Settings.HTTP_AUTH_USERNAME)); - httpAuthPassword = (EditText) findViewById(R.id.http_auth_password); - httpAuthPassword.setText(settings.getKey(Settings.HTTP_AUTH_PASSWORD)); - - TextWatcher textWatcher = new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { } - - @Override - public void afterTextChanged(Editable s) { - updateButton(); - } - }; - - editPocheUrl.addTextChangedListener(textWatcher); - editAPIUsername.addTextChangedListener(textWatcher); - editAPIToken.addTextChangedListener(textWatcher); - - progressDialog = new ProgressDialog(this); - progressDialog.setCanceledOnTouchOutside(true); - progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - cancelTasks(); - } - }); - - btnTestConnection = (Button) findViewById(R.id.btnTestConnection); - btnTestConnection.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - cancelTask(testConnectionTask); - - progressDialog.setMessage(getString(R.string.settings_testingConnection)); - progressDialog.show(); - - applyHttpAuth(); - - testConnectionTask = new TestConnectionTask( - SettingsActivity.this, editPocheUrl.getText().toString(), - username.getText().toString(), password.getText().toString(), - progressDialog); - - testConnectionTask.execute(); - } - }); - - btnGetCredentials = (Button) findViewById(R.id.btnGetFeedsCredentials); - btnGetCredentials.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - cancelTask(getCredentialsTask); - - progressDialog.setMessage(getString(R.string.settings_gettingCredentials)); - progressDialog.show(); - - applyHttpAuth(); - - getCredentialsTask = new GetCredentialsTask( - SettingsActivity.this, editPocheUrl.getText().toString(), - username.getText().toString(), password.getText().toString(), - editAPIUsername, editAPIToken, progressDialog); - - getCredentialsTask.execute(); - } - }); - - btnDone = (Button) findViewById(R.id.btnDone); - btnDone.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - wallabagSettings.wallabagURL = editPocheUrl.getText().toString(); - wallabagSettings.userID = editAPIUsername.getText().toString(); - wallabagSettings.userToken = editAPIToken.getText().toString(); + protected void onCreate(Bundle savedInstanceState) { + Themes.applyTheme(this); + super.onCreate(savedInstanceState); + setContentView(R.layout.settings); + + settings = App.getInstance().getSettings(); + wallabagSettings = WallabagSettings.settingsFromDisk(settings); + + if (!wallabagSettings.isValid()) { + hideBackButtonToActionBar(); + } + + editPocheUrl = (EditText) findViewById(R.id.pocheUrl); + editAPIUsername = (EditText) findViewById(R.id.APIUsername); + editAPIToken = (EditText) findViewById(R.id.APIToken); + allCerts = (CheckBox) findViewById(R.id.accept_all_certs_cb); + themeChooser = (AppCompatSpinner) findViewById(R.id.themeChooser); + fontSizeET = (EditText) findViewById(R.id.fontSizeET); + serifFont = (CheckBox) findViewById(R.id.ui_font_serif); + listLimit = (EditText) findViewById(R.id.list_limit_number); + + editPocheUrl.setText(wallabagSettings.wallabagURL); + editPocheUrl.setSelection(editPocheUrl.getText().length()); + editAPIUsername.setText(wallabagSettings.userID); + editAPIToken.setText(wallabagSettings.userToken); + allCerts.setChecked(settings.getBoolean(Settings.ALL_CERTS, false)); + + Themes.Theme[] themes = Themes.Theme.values(); + String[] themeOptions = new String[themes.length]; + Themes.Theme currentThemeName = Themes.getCurrentTheme(); + int currentThemeIndex = 0; + for(int i = 0; i < themes.length; i++) { + if(themes[i] == currentThemeName) currentThemeIndex = i; + themeOptions[i] = getString(themes[i].getNameId()); + } + themeChooser.setAdapter(new ArrayAdapter<>( + this, android.R.layout.simple_spinner_item, themeOptions)); + themeChooser.setSelection(currentThemeIndex); + + fontSizeET.setText(String.valueOf(settings.getInt(Settings.FONT_SIZE, 100))); + + serifFont.setChecked(settings.getBoolean(Settings.SERIF_FONT, false)); + listLimit.setText(String.valueOf(settings.getInt(Settings.LIST_LIMIT, 50))); + + username = (EditText) findViewById(R.id.username); + username.setText(settings.getKey(Settings.USERNAME)); + password = (EditText) findViewById(R.id.password); + password.setText(settings.getKey(Settings.PASSWORD)); + + httpAuthUsername = (EditText) findViewById(R.id.http_auth_username); + httpAuthUsername.setText(settings.getKey(Settings.HTTP_AUTH_USERNAME)); + httpAuthPassword = (EditText) findViewById(R.id.http_auth_password); + httpAuthPassword.setText(settings.getKey(Settings.HTTP_AUTH_PASSWORD)); + + TextWatcher textWatcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { } + + @Override + public void afterTextChanged(Editable s) { + updateButton(); + } + }; + + editPocheUrl.addTextChangedListener(textWatcher); + editAPIUsername.addTextChangedListener(textWatcher); + editAPIToken.addTextChangedListener(textWatcher); + + progressDialog = new ProgressDialog(this); + progressDialog.setCanceledOnTouchOutside(true); + progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + cancelTasks(); + } + }); + + btnTestConnection = (Button) findViewById(R.id.btnTestConnection); + btnTestConnection.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + cancelTask(testConnectionTask); + + progressDialog.setMessage(getString(R.string.settings_testingConnection)); + progressDialog.show(); + + applyHttpAuth(); + + testConnectionTask = new TestConnectionTask( + SettingsActivity.this, editPocheUrl.getText().toString(), + username.getText().toString(), password.getText().toString(), + progressDialog); + + testConnectionTask.execute(); + } + }); + + btnGetCredentials = (Button) findViewById(R.id.btnGetFeedsCredentials); + btnGetCredentials.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + cancelTask(getCredentialsTask); + + progressDialog.setMessage(getString(R.string.settings_gettingCredentials)); + progressDialog.show(); + + applyHttpAuth(); + + getCredentialsTask = new GetCredentialsTask( + SettingsActivity.this, editPocheUrl.getText().toString(), + username.getText().toString(), password.getText().toString(), + editAPIUsername, editAPIToken, progressDialog); + + getCredentialsTask.execute(); + } + }); + + btnDone = (Button) findViewById(R.id.btnDone); + btnDone.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + wallabagSettings.wallabagURL = editPocheUrl.getText().toString(); + wallabagSettings.userID = editAPIUsername.getText().toString(); + wallabagSettings.userToken = editAPIToken.getText().toString(); settings.setBoolean(Settings.ALL_CERTS, allCerts.isChecked()); - Themes.Theme selectedTheme = Themes.Theme.values()[themeChooser.getSelectedItemPosition()]; - settings.setString(Settings.THEME, selectedTheme.toString()); - settings.setInt(Settings.FONT_SIZE, fontSizeChooser.getSelectedItemPosition()); - settings.setBoolean(Settings.SERIF_FONT, serifFont.isChecked()); + Themes.Theme selectedTheme = Themes.Theme.values()[themeChooser.getSelectedItemPosition()]; + settings.setString(Settings.THEME, selectedTheme.toString()); + try { + settings.setInt(Settings.FONT_SIZE, Integer.parseInt(fontSizeET.getText().toString())); + } catch(NumberFormatException ignored) {} + settings.setBoolean(Settings.SERIF_FONT, serifFont.isChecked()); try { settings.setInt(Settings.LIST_LIMIT, Integer.parseInt(listLimit.getText().toString())); } catch (NumberFormatException ignored) {} @@ -196,94 +196,94 @@ public void onClick(View v) { settings.setString(Settings.USERNAME, username.getText().toString()); settings.setString(Settings.PASSWORD, password.getText().toString()); - applyHttpAuth(); - - settings.setString(Settings.HTTP_AUTH_USERNAME, httpAuthUsername.getText().toString()); - settings.setString(Settings.HTTP_AUTH_PASSWORD, httpAuthPassword.getText().toString()); - - if (wallabagSettings.isValid()) { - wallabagSettings.save(); - finish(); - - if(selectedTheme != Themes.getCurrentTheme()) { - Themes.init(); - - Intent intent = new Intent(SettingsActivity.this, ArticlesListActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - } - } - } - }); - - textViewVersion = (TextView) findViewById(R.id.version); - textViewVersion.setText(BuildConfig.VERSION_NAME); - - this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); - - updateButton(); - } - - @Override - protected void onStop() { - super.onStop(); - - cancelTasks(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.option_settings, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menuWipeDb: { - AlertDialog.Builder b = new AlertDialog.Builder(this); - b.setTitle(R.string.wipe_db_dialog_title); - b.setMessage(R.string.wipe_db_dialog_message); - b.setPositiveButton(R.string.positive_answer, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DbConnection.getSession().getArticleDao().deleteAll(); - } - }); - b.setNegativeButton(R.string.negative_answer, null); - b.create().show(); - return true; - } - } - - return super.onOptionsItemSelected(item); - } - - private void cancelTasks() { - cancelTask(testConnectionTask); - cancelTask(getCredentialsTask); - } - - private void cancelTask(AsyncTask task) { - if(task != null) { - task.cancel(true); - } - } - - private void applyHttpAuth() { - String username = httpAuthUsername.getText().toString(); - String password = httpAuthPassword.getText().toString(); - - WallabagConnection.setBasicAuthCredentials(username, password); - } - - // TODO: remove? - private void updateButton() { - wallabagSettings.wallabagURL = editPocheUrl.getText().toString(); - wallabagSettings.userID = editAPIUsername.getText().toString(); - wallabagSettings.userToken = editAPIToken.getText().toString(); - - btnDone.setEnabled(wallabagSettings.isValid()); - } + applyHttpAuth(); + + settings.setString(Settings.HTTP_AUTH_USERNAME, httpAuthUsername.getText().toString()); + settings.setString(Settings.HTTP_AUTH_PASSWORD, httpAuthPassword.getText().toString()); + + if (wallabagSettings.isValid()) { + wallabagSettings.save(); + finish(); + + if(selectedTheme != Themes.getCurrentTheme()) { + Themes.init(); + + Intent intent = new Intent(SettingsActivity.this, ArticlesListActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + } + } + } + }); + + textViewVersion = (TextView) findViewById(R.id.version); + textViewVersion.setText(BuildConfig.VERSION_NAME); + + this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + + updateButton(); + } + + @Override + protected void onStop() { + super.onStop(); + + cancelTasks(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.option_settings, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menuWipeDb: { + AlertDialog.Builder b = new AlertDialog.Builder(this); + b.setTitle(R.string.wipe_db_dialog_title); + b.setMessage(R.string.wipe_db_dialog_message); + b.setPositiveButton(R.string.positive_answer, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + DbConnection.getSession().getArticleDao().deleteAll(); + } + }); + b.setNegativeButton(R.string.negative_answer, null); + b.create().show(); + return true; + } + } + + return super.onOptionsItemSelected(item); + } + + private void cancelTasks() { + cancelTask(testConnectionTask); + cancelTask(getCredentialsTask); + } + + private void cancelTask(AsyncTask task) { + if(task != null) { + task.cancel(true); + } + } + + private void applyHttpAuth() { + String username = httpAuthUsername.getText().toString(); + String password = httpAuthPassword.getText().toString(); + + WallabagConnection.setBasicAuthCredentials(username, password); + } + + // TODO: remove? + private void updateButton() { + wallabagSettings.wallabagURL = editPocheUrl.getText().toString(); + wallabagSettings.userID = editAPIUsername.getText().toString(); + wallabagSettings.userToken = editAPIToken.getText().toString(); + + btnDone.setEnabled(wallabagSettings.isValid()); + } } diff --git a/app/src/main/res/layout/settings.xml b/app/src/main/res/layout/settings.xml index 981192a01..6d6d363ff 100644 --- a/app/src/main/res/layout/settings.xml +++ b/app/src/main/res/layout/settings.xml @@ -221,18 +221,19 @@ android:layout_height="wrap_content" android:paddingBottom="5sp" /> - - - + android:layout_height="wrap_content"> + + + + + diff --git a/app/src/main/res/raw/webview_htmlbase.html b/app/src/main/res/raw/webview_htmlbase.html new file mode 100644 index 000000000..9de761956 --- /dev/null +++ b/app/src/main/res/raw/webview_htmlbase.html @@ -0,0 +1,24 @@ + + + + + + + +
+ +
+
+
+

%3$s

+ + %5$s +
+
+ %6$s +
+
+
+ +
+ \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 3b086ad97..06fdcb3b2 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -49,7 +49,6 @@ GAULUPEAU Jonathan — 2013-2015 Keine Artikel Akzeptiere alle SSL Zertifikate Erfordert vielleicht Neustart; unsicher; Beachte, dass selbst-signierte Zertifikate in Android importiert werden müssen. - Hoher Kontrast für Text Limit für Artikel-Liste Laden… Wähle eine Aktion für die URL diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index ea30420bb..906fe9edb 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1,7 +1,6 @@ -Bienvenue sur wallabag -wallabag + wallabag Sauvegarder GAULUPEAU Jonathan — 2013 @@ -49,8 +48,7 @@ GAULUPEAU Jonathan — 2013 Aucun article Accepter tous les certificats SSL Peut nécessiter un redémarrage. Non sécurisé. Vous devriez plutôt ajouter vos certificats personnels au système. -Texte en contraste élevé -Limitation du nombre d\'articles dans la liste + Limitation du nombre d\'articles dans la liste Chargement… Choisissez une action pour l\'URL Ouvrir dans le navigateur @@ -134,4 +132,7 @@ GAULUPEAU Jonathan — 2013 Sombre (contraste élevé) Clair Clair (contraste élevé) + Diminuer la taille de la police + Augmenter la taille de la police + Famille de police (sans/avec serif) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 02516eba8..45a45c9eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,17 +126,13 @@ GAULUPEAU Jonathan — 2013-2015 Light (high contrast) Dark Dark (high contrast) - Article font size + Article font size (%) Serif typeface for article fonts + Increase font size + Decrease font size + Switch font family %d Article %d Articles - - 75% - 100% - 125% - 150% - 175% -