diff --git a/LICENSE.md b/LICENSE.md index a7d46a91..7dce67d7 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,18 +1,18 @@ -First of all: I am not a developer. I understand a few basics and most of my work is done -by copy and paste. This app is a fork of the original [Diaspora-Native-Webapp](https://github.com/martinchodev/Diaspora-Native-WebApp) -from "martinchodev" (who did most of the work -> big thanks to him), which is released under the GPL-license. +# App - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see http://www.gnu.org/licenses/. +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/. + +# Splashscreen-Images The splashscreen images can be found on [flickr](https://www.flickr.com/photos/129581906@N06/sets/72157651933980136/with/16594947123/). diff --git a/app/build.gradle b/app/build.gradle index 0d1e638c..3072760b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,9 +30,9 @@ dependencies { testCompile 'junit:junit:4.12' // Android standard libs - compile 'com.android.support:appcompat-v7:23.3.0' - compile 'com.android.support:design:23.3.0' - compile 'com.android.support:support-v4:23.3.0' + compile 'com.android.support:appcompat-v7:23.4.0' + compile 'com.android.support:design:23.4.0' + compile 'com.android.support:support-v4:23.4.0' // More libraries compile 'com.getbase:floatingactionbutton:1.9.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9fe46480..451dad0e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,10 +31,11 @@ android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/title_activity_pods" android:screenOrientation="portrait" + android:theme="@style/AppTheme.NoActionBar" android:windowSoftInputMode="stateHidden" > = Build.VERSION_CODES.LOLLIPOP) { + cookieManager.removeAllCookies(null); + } + } + public AppSettings getSettings() { return appSettings; } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java index 5b49065e..4f288183 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java @@ -1,18 +1,18 @@ /* - This file is part of the Diaspora Native WebApp. + This file is part of the Diaspora for Android. - Diaspora Native WebApp is free software: you can redistribute it and/or modify + Diaspora for Android is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Diaspora Native WebApp is distributed in the hope that it will be useful, + Diaspora for Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with the Diaspora Native WebApp. + along with the Diaspora for Android. If not, see . */ @@ -51,18 +51,15 @@ import android.text.Html; import android.text.SpannableString; import android.text.method.LinkMovementMethod; import android.text.util.Linkify; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.webkit.CookieManager; import android.webkit.JavascriptInterface; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; -import android.webkit.WebViewClient; import android.widget.EditText; import android.widget.ImageView; import android.widget.ProgressBar; @@ -75,10 +72,11 @@ import com.getbase.floatingactionbutton.FloatingActionsMenu; import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; -import com.github.dfa.diaspora_android.data.WebUserProfile; +import com.github.dfa.diaspora_android.data.PodUserProfile; import com.github.dfa.diaspora_android.listener.SoftKeyboardStateWatcher; import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener; import com.github.dfa.diaspora_android.ui.ContextMenuWebView; +import com.github.dfa.diaspora_android.ui.CustomWebViewClient; import com.github.dfa.diaspora_android.util.Helpers; import org.json.JSONException; @@ -113,8 +111,9 @@ public class MainActivity extends AppCompatActivity private String mCameraPhotoPath; private WebSettings webSettings; private AppSettings appSettings; - private WebUserProfile webUserProfile; + private PodUserProfile podUserProfile; private final Handler uiHandler = new Handler(); + private CustomWebViewClient webViewClient; @BindView(R.id.swipe) SwipeRefreshLayout swipeRefreshLayout; @@ -151,7 +150,7 @@ public class MainActivity extends AppCompatActivity app = (App) getApplication(); appSettings = app.getSettings(); - webUserProfile = new WebUserProfile(app, uiHandler, this); + podUserProfile = new PodUserProfile(app, uiHandler, this); this.registerForContextMenu(webView); webView.setParentActivity(this); @@ -216,37 +215,8 @@ public class MainActivity extends AppCompatActivity /* * WebViewClient */ - webView.setWebViewClient(new WebViewClient() { - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (!url.contains(podDomain)) { - Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - startActivity(i); - return true; - } - return false; - } - - public void onPageFinished(WebView view, String url) { - swipeRefreshLayout.setRefreshing(false); - - - final CookieManager cookieManager = app.getCookieManager(); - String cookies = cookieManager.getCookie(url); - Log.d(App.TAG, "All the cookies in a string:" + cookies); - - if (cookies != null) { - cookieManager.setCookie(url, cookies); - cookieManager.setCookie("https://" + appSettings.getPodDomain(), cookies); - for (String c : cookies.split(";")) { - //Log.d(App.TAG, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]); - } - //new ProfileFetchTask(app).execute(); - } - - } - - - }); + webViewClient = new CustomWebViewClient(app, swipeRefreshLayout, webView); + webView.setWebViewClient(webViewClient); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override @@ -842,6 +812,9 @@ public class MainActivity extends AppCompatActivity uiHandler.post(new Runnable() { @Override public void run() { + if(menu == null){ + return; + } notificationCount = Integer.valueOf(webMessage); MenuItem item = menu.findItem(R.id.action_notifications); @@ -875,8 +848,8 @@ public class MainActivity extends AppCompatActivity @JavascriptInterface public void setUserProfile(final String webMessage) throws JSONException { - if (webUserProfile.isRefreshNeeded()) { - webUserProfile.parseJson(webMessage); + if (podUserProfile.isRefreshNeeded()) { + podUserProfile.parseJson(webMessage); } } @@ -885,6 +858,9 @@ public class MainActivity extends AppCompatActivity uiHandler.post(new Runnable() { @Override public void run() { + if(menu == null){ + return; + } conversationCount = Integer.valueOf(webMessage); MenuItem item = menu.findItem(R.id.action_conversations); @@ -1038,23 +1014,15 @@ public class MainActivity extends AppCompatActivity new AlertDialog.Builder(MainActivity.this) .setTitle(getString(R.string.confirmation)) .setMessage(getString(R.string.change_pod_warning)) - .setPositiveButton(getString(R.string.yes), + .setNegativeButton(android.R.string.no, null) + .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @TargetApi(11) public void onClick(DialogInterface dialog, int id) { - webView.clearCache(true); - dialog.cancel(); - Intent i = new Intent(MainActivity.this, PodSelectionActivity.class); - startActivity(i); - finish(); + app.resetPodData(webView); + Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true); } }) - .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { - @TargetApi(11) - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }).show(); + .show(); break; } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/PodSelectionActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/PodSelectionActivity.java index 51df9c50..df32e9e8 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/PodSelectionActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/PodSelectionActivity.java @@ -1,18 +1,18 @@ /* - This file is part of the Diaspora Native WebApp. + This file is part of the Diaspora for Android. - Diaspora Native WebApp is free software: you can redistribute it and/or modify + Diaspora for Android is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Diaspora Native WebApp is distributed in the hope that it will be useful, + Diaspora for Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with the Diaspora Native WebApp. + along with the Diaspora for Android. If not, see . */ @@ -29,7 +29,9 @@ import android.content.IntentFilter; import android.os.Build; import android.os.Bundle; import android.support.design.widget.Snackbar; +import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.SpannableString; import android.text.TextWatcher; @@ -38,11 +40,9 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.CookieManager; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; -import android.widget.TextView; import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; @@ -50,25 +50,24 @@ import com.github.dfa.diaspora_android.task.GetPodsService; import com.github.dfa.diaspora_android.util.Helpers; import java.util.ArrayList; -import java.util.Collections; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; +import butterknife.OnItemClick; public class PodSelectionActivity extends AppCompatActivity { - private BroadcastReceiver podListReceiver; private App app; @BindView(R.id.podselection__edit_filter) - public EditText filter; + public EditText editFilter; @BindView(R.id.podselection__listpods) - public ListView lv; - - private String podSelected = ""; + public ListView listPods; + @BindView(R.id.toolbar) + public Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { @@ -76,37 +75,40 @@ public class PodSelectionActivity extends AppCompatActivity { setContentView(R.layout.podselection_activity); ButterKnife.bind(this); app = (App) getApplication(); - lv.setTextFilterEnabled(true); + setSupportActionBar(toolbar); - podListReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (intent.hasExtra("pods")) { - Bundle extras = intent.getExtras(); - String[] pods = extras.getStringArray("pods"); - - if (pods != null && pods.length > 0) - updateListview(pods); - else { - Snackbar.make(lv, R.string.podlist_error, Snackbar.LENGTH_LONG).show(); - } - } - } - }; + listPods.setTextFilterEnabled(true); registerReceiver(podListReceiver, new IntentFilter(GetPodsService.MESSAGE)); if (!Helpers.isOnline(PodSelectionActivity.this)) { - Snackbar.make(lv, R.string.no_internet, Snackbar.LENGTH_LONG).show(); + Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show(); } } + + private final BroadcastReceiver podListReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.hasExtra("pods")) { + Bundle extras = intent.getExtras(); + String[] pods = extras.getStringArray("pods"); + + if (pods != null && pods.length > 0) + setListedPods(pods); + else { + Snackbar.make(listPods, R.string.podlist_error, Snackbar.LENGTH_LONG).show(); + } + } + } + }; + @OnClick(R.id.podselection__button_select_pod) public void onButtonSelectPodClicked(View view) { - if (filter.getText().length() > 4 && filter.getText().toString().contains("")) { - askConfirmation(filter.getText().toString()); + if (editFilter.getText().length() > 4 && editFilter.getText().toString().contains("")) { + showPodConfirmationDialog(editFilter.getText().toString()); } else { - Snackbar.make(lv, R.string.valid_pod, Snackbar.LENGTH_LONG).show(); + Snackbar.make(listPods, R.string.valid_pod, Snackbar.LENGTH_LONG).show(); } } @@ -118,72 +120,72 @@ public class PodSelectionActivity extends AppCompatActivity { } - private void updateListview(String[] allPods) { - final ArrayList podList = new ArrayList<>(); + private void setListedPods(String[] listedPodsArr) { + final ArrayList listedPodsList = new ArrayList<>(); - for (String pod : allPods) { - podList.add(pod.toLowerCase()); + for (String pod : listedPodsArr) { + listedPodsList.add(pod.toLowerCase()); } - //Collections.sort(podList); final ArrayAdapter adapter = new ArrayAdapter<>( PodSelectionActivity.this, android.R.layout.simple_list_item_1, - podList); - lv.setAdapter(adapter); - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - askConfirmation(((TextView) view).getText().toString()); - } - }); + listedPodsList); + listPods.setAdapter(adapter); - adapter.getFilter().filter(filter.getText()); - filter.addTextChangedListener(new TextWatcher() { + adapter.getFilter().filter(editFilter.getText()); + editFilter.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { (adapter).getFilter().filter(s.toString()); } + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } + public void afterTextChanged(Editable s) { } }); } - private void askConfirmation(final String podDomain) { - podSelected = podDomain; - - // Make link clickable - final SpannableString dialogMessage = new SpannableString(getString(R.string.confirm_pod, podDomain)); - Linkify.addLinks(dialogMessage, Linkify.ALL); - - if (Helpers.isOnline(PodSelectionActivity.this)) { - new AlertDialog.Builder(PodSelectionActivity.this) - .setTitle(getString(R.string.confirmation)) - .setMessage(dialogMessage) - .setPositiveButton(R.string.yes, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - onPodSelectionConfirmed(); - } - }) - .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { - @TargetApi(11) - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - podSelected = ""; - } - }).show(); - - } else { - Snackbar.make(lv, R.string.no_internet, Snackbar.LENGTH_LONG).show(); - } + @OnItemClick(R.id.podselection__listpods) + public void onListPodsItemClicked(int position) { + showPodConfirmationDialog((String) listPods.getAdapter().getItem(position)); } - public void onPodSelectionConfirmed(){ - app.getSettings().setPodDomain(podSelected); + private void showPodConfirmationDialog(final String selectedPod) { + // Make a clickable link + final SpannableString dialogMessage = new SpannableString(getString(R.string.confirm_pod, selectedPod)); + Linkify.addLinks(dialogMessage, Linkify.ALL); + + // Check if online + if (!Helpers.isOnline(PodSelectionActivity.this)) { + Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show(); + return; + } + + // Show dialog + new AlertDialog.Builder(PodSelectionActivity.this) + .setTitle(getString(R.string.confirmation)) + .setMessage(dialogMessage) + .setPositiveButton(R.string.yes, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + onPodSelectionConfirmed(selectedPod); + } + }) + .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { + @TargetApi(11) + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }) + .show(); + } + + public void onPodSelectionConfirmed(String selectedPod) { + app.getSettings().setPodDomain(selectedPod); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { CookieManager.getInstance().removeAllCookies(null); @@ -200,20 +202,16 @@ public class PodSelectionActivity extends AppCompatActivity { } } - Intent intent = new Intent(PodSelectionActivity.this, MainActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - startActivity(intent); - overridePendingTransition(R.anim.fadein, R.anim.fadeout); - finish(); + Helpers.animateToActivity(this, MainActivity.class, true); } @Override public void onBackPressed() { - Snackbar.make(lv, R.string.confirm_exit, Snackbar.LENGTH_LONG) - .setAction(R.string.yes, new View.OnClickListener() { + Snackbar.make(listPods, R.string.confirm_exit, Snackbar.LENGTH_LONG) + .setAction(android.R.string.yes, new View.OnClickListener() { public void onClick(View view) { - moveTaskToBack(true); + finish(); } }) .show(); @@ -240,15 +238,13 @@ public class PodSelectionActivity extends AppCompatActivity { startService(i); return true; } else { - Snackbar.make(lv, R.string.no_internet, Snackbar.LENGTH_LONG).show(); + Snackbar.make(listPods, R.string.no_internet, Snackbar.LENGTH_LONG).show(); return false; } } } return super.onOptionsItemSelected(item); } - - } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java index 3a6560f1..76275e88 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/ShareActivity.java @@ -1,18 +1,18 @@ /* - This file is part of the Diaspora Native WebApp. + This file is part of the Diaspora for Android. - Diaspora Native WebApp is free software: you can redistribute it and/or modify + Diaspora for Android is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Diaspora Native WebApp is distributed in the hope that it will be useful, + Diaspora for Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with the Diaspora Native WebApp. + along with the Diaspora for Android. If not, see . */ diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/SplashActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/SplashActivity.java index ac93bdbd..021caa54 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/SplashActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/SplashActivity.java @@ -1,74 +1,67 @@ /* - This file is part of the Diaspora Native WebApp. + This file is part of the Diaspora for Android. - Diaspora Native WebApp is free software: you can redistribute it and/or modify + Diaspora for Android is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Diaspora Native WebApp is distributed in the hope that it will be useful, + Diaspora for Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with the Diaspora Native WebApp. + along with the Diaspora for Android. If not, see . */ package com.github.dfa.diaspora_android.activity; -import android.content.Intent; import android.content.res.TypedArray; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActivity; -import android.view.WindowManager; import android.widget.ImageView; import com.github.dfa.diaspora_android.App; import com.github.dfa.diaspora_android.R; +import com.github.dfa.diaspora_android.util.Helpers; -import java.util.Timer; -import java.util.TimerTask; +import butterknife.BindView; +import butterknife.ButterKnife; public class SplashActivity extends AppCompatActivity { private App app; + @BindView(R.id.splash__splashimage) + public ImageView imgSplash; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_activity); + ButterKnife.bind(this); app = (App) getApplication(); - ImageView imgSplash = (ImageView) findViewById(R.id.splash__splashimage); - TypedArray images = getResources().obtainTypedArray(R.array.splash_images); int choice = (int) (Math.random() * images.length()); imgSplash.setImageResource(images.getResourceId(choice, R.drawable.splashscreen1)); images.recycle(); int delay = getResources().getInteger(R.integer.splash_delay); - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - - Intent intent; - if (!app.getSettings().getPodDomain().equals("")) { - intent = new Intent(SplashActivity.this, MainActivity.class); - } else { - intent = new Intent(SplashActivity.this, PodSelectionActivity.class); - } - intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - startActivity(intent); - overridePendingTransition(R.anim.fadein, R.anim.fadeout); - finish(); - } - }, delay); - + new Handler().postDelayed(startActivityRunnable, delay); } + final Runnable startActivityRunnable = new Runnable() { + public void run() { + boolean hasPodDomain = app.getSettings().hasPodDomain(); + Helpers.animateToActivity(SplashActivity.this, + hasPodDomain ? MainActivity.class : PodSelectionActivity.class, + true + ); + } + }; } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java index 873fcf12..0d0138af 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java @@ -4,92 +4,106 @@ import android.content.Context; import android.content.SharedPreferences; /** - * Created by gsantner on 20.03.16. Part of Diaspora WebApp. + * Created by gsantner on 20.03.16. Part of Diaspora for Android. */ public class AppSettings { - private final SharedPreferences pref; + private final SharedPreferences prefApp; + private final SharedPreferences prefPod; private final Context context; public AppSettings(Context context) { this.context = context.getApplicationContext(); - pref = this.context.getSharedPreferences("app", Context.MODE_PRIVATE); + prefApp = this.context.getSharedPreferences("app", Context.MODE_PRIVATE); + prefPod = this.context.getSharedPreferences("pod0", Context.MODE_PRIVATE); } - private void setString(String key, String value) { + public void clearPodSettings() { + prefPod.edit().clear().apply(); + } + + public void clearAppSettings() { + prefApp.edit().clear().apply(); + } + + private void setString(SharedPreferences pref, String key, String value) { pref.edit().putString(key, value).apply(); } - private void setInt(String key, int value) { + private void setInt(SharedPreferences pref, String key, int value) { pref.edit().putInt(key, value).apply(); } - private void setBool(String key, boolean value) { + private void setBool(SharedPreferences pref, String key, boolean value) { pref.edit().putBoolean(key, value).apply(); } /* // Preferences */ - private static final String PREF_WEBUSERPROFILE_ID = "webUserProfile_guid"; - private static final String PREF_IS_LOAD_IMAGES = "loadImages"; - private static final String PREF_MINIMUM_FONT_SIZE = "minimumFontSize"; - private static final String PREF_AVATAR_URL = "webUserProfile_avatar"; - private static final String PREF_WEBUSERPROFILE_NAME = "webUserProfile_name"; - private static final String PREF_PODDOMAIN = "podDomain"; + public static class PREF { + private static final String IS_LOAD_IMAGES = "loadImages"; + private static final String MINIMUM_FONT_SIZE = "minimumFontSize"; + private static final String PODUSERPROFILE_AVATAR_URL = "podUserProfile_avatar"; + private static final String PODUSERPROFILE_NAME = "podUserProfile_name"; + private static final String PODUSERPROFILE_ID = "podUserProfile_guid"; + private static final String PODDOMAIN = "podDomain"; + } /* // Setters & Getters */ public String getProfileId() { - return pref.getString(PREF_WEBUSERPROFILE_ID, ""); + return prefPod.getString(PREF.PODUSERPROFILE_ID, ""); } public void setProfileId(String profileId) { - setString(PREF_WEBUSERPROFILE_ID, profileId); + setString(prefPod, PREF.PODUSERPROFILE_ID,profileId); } public boolean isLoadImages() { - return pref.getBoolean(PREF_IS_LOAD_IMAGES, true); + return prefApp.getBoolean(PREF.IS_LOAD_IMAGES, true); } public void setLoadImages(boolean loadImages) { - setBool(PREF_IS_LOAD_IMAGES, loadImages); + setBool(prefApp, PREF.IS_LOAD_IMAGES, loadImages); } public int getMinimumFontSize() { - return pref.getInt(PREF_MINIMUM_FONT_SIZE, 8); + return prefApp.getInt(PREF.MINIMUM_FONT_SIZE, 8); } public void setMinimumFontSize(int minimumFontSize) { - setInt(PREF_MINIMUM_FONT_SIZE, minimumFontSize); + setInt(prefApp, PREF.MINIMUM_FONT_SIZE, minimumFontSize); } public String getAvatarUrl() { - return pref.getString(PREF_AVATAR_URL, ""); + return prefPod.getString(PREF.PODUSERPROFILE_AVATAR_URL, ""); } public void setAvatarUrl(String avatarUrl) { - setString(PREF_AVATAR_URL, avatarUrl); + setString(prefPod, PREF.PODUSERPROFILE_AVATAR_URL, avatarUrl); } public String getName() { - return pref.getString(PREF_WEBUSERPROFILE_NAME, ""); + return prefPod.getString(PREF.PODUSERPROFILE_NAME, ""); } public void setName(String name) { - setString(PREF_WEBUSERPROFILE_NAME, name); + setString(prefPod, PREF.PODUSERPROFILE_NAME, name); } public String getPodDomain() { - return pref.getString(PREF_PODDOMAIN, ""); + return prefPod.getString(PREF.PODDOMAIN, ""); } public void setPodDomain(String podDomain) { - setString(PREF_PODDOMAIN, podDomain); + setString(prefPod, PREF.PODDOMAIN, podDomain); } - + public boolean hasPodDomain(){ + return !prefPod.getString(PREF.PODDOMAIN, "").equals(""); + } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/WebUserProfile.java b/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java similarity index 96% rename from app/src/main/java/com/github/dfa/diaspora_android/data/WebUserProfile.java rename to app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java index 92b72d0b..68c5362d 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/WebUserProfile.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/PodUserProfile.java @@ -10,9 +10,9 @@ import org.json.JSONException; import org.json.JSONObject; /** - * Created by gsantner on 24.03.16. Part of Diaspora WebApp. + * Created by gsantner on 24.03.16. Part of Diaspora for Android. */ -public class WebUserProfile { +public class PodUserProfile { private static final int MINIMUM_WEBUSERPROFILE_LOAD_TIMEDIFF = 5000; private Handler callbackHandler; @@ -30,7 +30,7 @@ public class WebUserProfile { private int unreadMessagesCount; - public WebUserProfile(App app) { + public PodUserProfile(App app) { this.app = app; appSettings = app.getSettings(); @@ -39,7 +39,7 @@ public class WebUserProfile { name = appSettings.getName(); } - public WebUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) { + public PodUserProfile(App app, Handler callbackHandler, WebUserProfileChangedListener listener) { this(app); this.listener = listener; this.callbackHandler = callbackHandler; diff --git a/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java b/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java index 8d3c119d..0e44d277 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/listener/SoftKeyboardStateWatcher.java @@ -1,7 +1,7 @@ package com.github.dfa.diaspora_android.listener; /** - * Created by juergen on 25.03.16. Part of Diaspora WebApp. + * Created by juergen on 25.03.16. Part of Diaspora for Android. * solution found on: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android */ diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java b/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java index 43822a24..fcc133c9 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/GetPodsService.java @@ -1,18 +1,18 @@ /* - This file is part of the Diaspora Native WebApp. + This file is part of the Diaspora for Android. - Diaspora Native WebApp is free software: you can redistribute it and/or modify + Diaspora for Android is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Diaspora Native WebApp is distributed in the hope that it will be useful, + Diaspora for Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with the Diaspora Native WebApp. + along with the Diaspora for Android. If not, see . */ diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java b/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java index df37cd28..2b5a3d23 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/ImageDownloadTask.java @@ -52,7 +52,7 @@ public class ImageDownloadTask extends AsyncTask { if (out != null) { out.close(); } - } catch (IOException e) { + } catch (IOException ignored) { } } return bitmap; diff --git a/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java b/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java index 6daee1ba..f54774f0 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/task/ProfileFetchTask.java @@ -6,7 +6,7 @@ import android.util.Log; import android.webkit.CookieManager; import com.github.dfa.diaspora_android.App; -import com.github.dfa.diaspora_android.data.WebUserProfile; +import com.github.dfa.diaspora_android.data.PodUserProfile; import java.io.BufferedReader; import java.io.IOException; @@ -63,7 +63,7 @@ public class ProfileFetchTask extends AsyncTask { if (extractedProfileData != null) { - WebUserProfile profile = new WebUserProfile(app); + PodUserProfile profile = new PodUserProfile(app); profile.parseJson(extractedProfileData); Log.d(App.TAG, "Extracted new_messages (service):" + profile.getUnreadMessagesCount()); } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java new file mode 100644 index 00000000..a17950af --- /dev/null +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/CustomWebViewClient.java @@ -0,0 +1,55 @@ +package com.github.dfa.diaspora_android.ui; + +import android.content.Intent; +import android.net.Uri; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.Log; +import android.webkit.CookieManager; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import com.github.dfa.diaspora_android.App; + +/** + * Created by Gregor Santner (gsantner) on 04.06.16. + */ +public class CustomWebViewClient extends WebViewClient { + private App app; + private SwipeRefreshLayout swipeRefreshLayout; + private WebView webView; + + public CustomWebViewClient(App app, SwipeRefreshLayout swipeRefreshLayout, WebView webView) { + this.app = app; + this.swipeRefreshLayout = swipeRefreshLayout; + this.webView = webView; + } + + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (!url.contains(app.getSettings().getPodDomain())) { + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + app.getApplicationContext().startActivity(i); + return true; + } + return false; + } + + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + swipeRefreshLayout.setRefreshing(false); + + final CookieManager cookieManager = app.getCookieManager(); + String cookies = cookieManager.getCookie(url); + //Log.d(App.TAG, "All the cookies in a string:" + cookies); + + if (cookies != null) { + cookieManager.setCookie(url, cookies); + cookieManager.setCookie("https://" + app.getSettings().getPodDomain(), cookies); + for (String c : cookies.split(";")) { + //Log.d(App.TAG, "Cookie: " + c.split("=")[0] + " Value:" + c.split("=")[1]); + } + //new ProfileFetchTask(app).execute(); + } + } + +} diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/FloatingActionsMenuBehavior.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/FloatingActionsMenuBehavior.java index 0100ee51..e7c8ddce 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/FloatingActionsMenuBehavior.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/FloatingActionsMenuBehavior.java @@ -1,7 +1,7 @@ package com.github.dfa.diaspora_android.ui; /** - * Created by juergen on 29.02.16. Part of Diaspora WebApp. + * Created by juergen on 29.02.16. Part of Diaspora for Android. */ import android.content.Context; diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/AvatarImageLoader.java b/app/src/main/java/com/github/dfa/diaspora_android/util/AvatarImageLoader.java index ea9cd3ce..e6a838b2 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/AvatarImageLoader.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/AvatarImageLoader.java @@ -16,13 +16,14 @@ public class AvatarImageLoader { private File avatarFile; public AvatarImageLoader(Context context) { - avatarFile = new File(context.getFilesDir(), "avatar.png"); + avatarFile = new File(context.getFilesDir(), "avatar0.png"); } - public void clearAvatarImage() { + public boolean clearAvatarImage() { if (isAvatarDownloaded()) { - avatarFile.delete(); + return avatarFile.delete(); } + return true; } public boolean loadToImageView(ImageView imageView) { diff --git a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java index c46317b5..b80250c2 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/util/Helpers.java @@ -1,18 +1,18 @@ /* - This file is part of the Diaspora Native WebApp. + This file is part of the Diaspora for Android. - Diaspora Native WebApp is free software: you can redistribute it and/or modify + Diaspora for Android is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Diaspora Native WebApp is distributed in the hope that it will be useful, + Diaspora for Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with the Diaspora Native WebApp. + along with the Diaspora for Android. If not, see . */ @@ -20,12 +20,17 @@ package com.github.dfa.diaspora_android.util; +import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.support.v4.content.ContextCompat; import android.webkit.WebView; +import com.github.dfa.diaspora_android.R; +import com.github.dfa.diaspora_android.activity.MainActivity; + public class Helpers { public static boolean isOnline(Context context) { @@ -34,6 +39,16 @@ public class Helpers { return ni != null && ni.isConnectedOrConnecting(); } + public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) { + Intent intent = new Intent(from, to); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + from.startActivity(intent); + from.overridePendingTransition(R.anim.fadein, R.anim.fadeout); + if (finishFromActivity) { + from.finish(); + } + } + public static void hideTopBar(final WebView wv) { wv.loadUrl("javascript: ( function() {" + " if(document.getElementById('main_nav')) {" + diff --git a/app/src/main/res/layout/podselection_activity.xml b/app/src/main/res/layout/podselection_activity.xml index 17274630..4a3be0a4 100644 --- a/app/src/main/res/layout/podselection_activity.xml +++ b/app/src/main/res/layout/podselection_activity.xml @@ -1,56 +1,94 @@ - + - + android:theme="@style/AppTheme.AppBarOverlay"> - + + + + + android:layout_height="match_parent" + android:paddingBottom="@dimen/activity_vertical_margin" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + app:layout_behavior="@string/appbar_scrolling_view_behavior" + tools:showIn="@layout/podselection_activity"> - + - - android:layout_alignParentStart="true" - android:text="@string/podlist_source_note" - android:textAppearance="?android:attr/textAppearanceSmall" - android:autoLink="web" /> + - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f754e963..92583ecc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -210,4 +210,5 @@ Open in external browser … Copy link address to clipboard Saving image to + https://