1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-22 19:08:03 +01:00

Lots of refactoring; Reworked Splash,PodSelectionActivity; Switch Pod; Clear settings;

This commit is contained in:
Gregor Santner 2016-06-04 03:48:57 +02:00
parent ff39986715
commit 280f5ab1c3
20 changed files with 389 additions and 281 deletions

View file

@ -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/).

View file

@ -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'

View file

@ -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" >
</activity>
<activity
android:name="com.github.dfa.diaspora_android.activity.MainActivity"
android:name=".activity.MainActivity"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboardHidden|orientation|screenSize"

View file

@ -3,10 +3,14 @@ package com.github.dfa.diaspora_android;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
import com.github.dfa.diaspora_android.util.AvatarImageLoader;
/**
@ -35,6 +39,28 @@ public class App extends Application {
cookieManager.setAcceptCookie(true);
}
public void resetPodData(@Nullable WebView webView){
if(webView != null){
webView.stopLoading();
webView.loadUrl("about:blank");
webView.clearFormData();
webView.clearHistory();
webView.clearCache(true);
}
// Clear avatar image
new AvatarImageLoader(this).clearAvatarImage();
// Clear preferences
appSettings.clearPodSettings();
// Clear cookies
cookieManager.removeAllCookie();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(null);
}
}
public AppSettings getSettings() {
return appSettings;
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
@ -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;
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
@ -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<String> podList = new ArrayList<>();
private void setListedPods(String[] listedPodsArr) {
final ArrayList<String> listedPodsList = new ArrayList<>();
for (String pod : allPods) {
podList.add(pod.toLowerCase());
for (String pod : listedPodsArr) {
listedPodsList.add(pod.toLowerCase());
}
//Collections.sort(podList);
final ArrayAdapter<String> 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);
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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
);
}
};
}

View file

@ -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("");
}
}

View file

@ -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;

View file

@ -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
*/

View file

@ -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 <http://www.gnu.org/licenses/>.
*/

View file

@ -52,7 +52,7 @@ public class ImageDownloadTask extends AsyncTask<String, Void, Bitmap> {
if (out != null) {
out.close();
}
} catch (IOException e) {
} catch (IOException ignored) {
}
}
return bitmap;

View file

@ -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<Void, Void, Void> {
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());
}

View file

@ -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();
}
}
}

View file

@ -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;

View file

@ -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) {

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
@ -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')) {" +

View file

@ -1,56 +1,94 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/podsLayout"
android:layout_width="match_parent"
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"
android:fitsSystemWindows="true"
tools:context=".activity.PodSelectionActivity">
<ListView
android:id="@+id/podselection__listpods"
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__podupti_notice"
android:layout_below="@+id/podselection__edit_filter"
android:choiceMode="singleChoice" />
android:theme="@style/AppTheme.AppBarOverlay">
<EditText
android:id="@+id/podselection__edit_filter"
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:id="@+id/podsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/podselection__button_select_pod"
android:layout_toStartOf="@+id/podselection__button_select_pod"
android:hint="@string/filter_hint"
android:inputType="textUri|textWebEditText" />
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">
<ImageView
android:id="@+id/podselection__button_select_pod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignEnd="@+id/podselection__listpods"
android:layout_alignRight="@+id/podselection__listpods"
android:layout_alignTop="@+id/podselection__edit_filter"
android:contentDescription="@string/confirm_url"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@mipmap/ic_arrow_right_grey600_24dp" />
<ListView
android:id="@+id/podselection__listpods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__podupti_notice"
android:layout_below="@+id/podselection__edit_filter"
android:choiceMode="singleChoice" />
<TextView
android:id="@+id/podselection__podupti_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
<EditText
android:id="@+id/podselection__edit_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView"
android:layout_toLeftOf="@+id/podselection__button_select_pod"
android:layout_toRightOf="@+id/textView"
android:hint="@string/filter_hint"
android:inputType="textUri|textWebEditText" />
android:layout_alignParentStart="true"
android:text="@string/podlist_source_note"
android:textAppearance="?android:attr/textAppearanceSmall"
android:autoLink="web" />
<ImageView
android:id="@+id/podselection__button_select_pod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignEnd="@+id/podselection__listpods"
android:layout_alignRight="@+id/podselection__listpods"
android:layout_alignTop="@+id/podselection__edit_filter"
android:contentDescription="@string/confirm_url"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@mipmap/ic_arrow_right_grey600_24dp" />
</RelativeLayout>
<TextView
android:id="@+id/podselection__podupti_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:autoLink="web"
android:text="@string/podlist_source_note"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/podselection__listpods"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:gravity="center_vertical"
android:text="@string/prefix_https"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -210,4 +210,5 @@
<string name="context_menu_open_external_browser">Open in external browser …</string>
<string name="context_menu_copy_link">Copy link address to clipboard</string>
<string name="toast_saved_image_to_location">Saving image to</string>
<string name="prefix_https" translatable="false">https://</string>
</resources>