mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 04:12:08 +01:00
WebUserProfile [WIP], App Object
This commit is contained in:
parent
7f780ac3ce
commit
9007045b28
5 changed files with 187 additions and 5 deletions
|
@ -10,6 +10,7 @@
|
|||
android:allowBackup="true"
|
||||
android:fullBackupContent="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:name=".App"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
|
|
21
app/src/main/java/de/baumann/diaspora/App.java
Normal file
21
app/src/main/java/de/baumann/diaspora/App.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package de.baumann.diaspora;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
/**
|
||||
* Created by gregor on 24.03.16.
|
||||
*/
|
||||
public class App extends Application {
|
||||
private AppSettings appSettings;
|
||||
public static final String APP_LOG_TAG = "DIASPORA_";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
appSettings = new AppSettings(getApplicationContext());
|
||||
}
|
||||
|
||||
public AppSettings getSettings() {
|
||||
return appSettings;
|
||||
}
|
||||
}
|
|
@ -68,6 +68,9 @@ import android.widget.RadioButton;
|
|||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -84,6 +87,7 @@ public class MainActivity extends AppCompatActivity
|
|||
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
||||
private static final String URL_MESSAGE = "URL_MESSAGE";
|
||||
|
||||
private App app;
|
||||
private final Handler myHandler = new Handler();
|
||||
private WebView webView;
|
||||
private String podDomain;
|
||||
|
@ -109,6 +113,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
setContentView(R.layout.activity_main);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
app = (App) getApplication();
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
toolbar.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -125,7 +130,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
|
||||
// Load app settings
|
||||
appSettings = new AppSettings(getApplicationContext());
|
||||
appSettings = app.getSettings();
|
||||
profileId = appSettings.getProfileId();
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
|
@ -207,6 +212,7 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
if (progress > 0 && progress <= 60) {
|
||||
Helpers.getNotificationCount(wv);
|
||||
Helpers.getUserProfile(wv);
|
||||
}
|
||||
|
||||
if (progress > 60) {
|
||||
|
@ -494,7 +500,7 @@ public class MainActivity extends AppCompatActivity
|
|||
case R.id.action_exit: {
|
||||
moveTaskToBack(true);
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
|
||||
case R.id.action_share: {
|
||||
final CharSequence[] options = {getString(R.string.share_link), getString(R.string.share_screenshot), getString(R.string.take_screenshot)};
|
||||
|
@ -630,7 +636,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}).show();
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -722,13 +728,20 @@ public class MainActivity extends AppCompatActivity
|
|||
|
||||
@JavascriptInterface
|
||||
public void setProfileId(final String webMessage) {
|
||||
if(profileId.equals("") || !profileId.equals(webMessage)) {
|
||||
if (profileId.equals("") || !profileId.equals(webMessage)) {
|
||||
profileId = webMessage;
|
||||
appSettings.setProfileId(profileId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@JavascriptInterface
|
||||
public void setUserProfile(final String webMessage) throws JSONException {
|
||||
JSONObject d = new JSONObject(webMessage);
|
||||
|
||||
int id = d.getInt("id");
|
||||
System.out.print(id);
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void setConversationCount(final String webMessage) {
|
||||
|
|
138
app/src/main/java/de/baumann/diaspora/WebUserProfile.java
Normal file
138
app/src/main/java/de/baumann/diaspora/WebUserProfile.java
Normal file
|
@ -0,0 +1,138 @@
|
|||
package de.baumann.diaspora;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by de-live-gdev on 24.03.16. Part of Diaspora WebApp.
|
||||
*/
|
||||
public class WebUserProfile {
|
||||
private final int MINIMUM_WEBUSERPROFILE_LOAD_TIMEDIFF = 5000;
|
||||
JSONObject json;
|
||||
long lastLoaded;
|
||||
boolean isWebUserProfileLoaded;
|
||||
|
||||
public WebUserProfile(){
|
||||
}
|
||||
|
||||
public boolean isRefreshNeeded(){
|
||||
return (System.currentTimeMillis() - lastLoaded) >= MINIMUM_WEBUSERPROFILE_LOAD_TIMEDIFF;
|
||||
}
|
||||
|
||||
public boolean isWebUserProfileLoaded() {
|
||||
return isWebUserProfileLoaded;
|
||||
}
|
||||
|
||||
public boolean loadFromJson(String json) {
|
||||
try {
|
||||
this.json = new JSONObject(json);
|
||||
lastLoaded = System.currentTimeMillis();
|
||||
isWebUserProfileLoaded = true;
|
||||
} catch (JSONException e) {
|
||||
Log.d(App.APP_LOG_TAG, e.getMessage());
|
||||
isWebUserProfileLoaded = false;
|
||||
}
|
||||
return isWebUserProfileLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Avatar URL's
|
||||
* @return Avatar URL's
|
||||
* [0] small
|
||||
* [1] medium
|
||||
* [2] large
|
||||
*/
|
||||
public String[] getAvatarUrls(){
|
||||
try {
|
||||
String[] avatars = new String[3];
|
||||
JSONObject o = json.getJSONObject("avatar");
|
||||
avatars[0] = o.getString("small");
|
||||
avatars[1] = o.getString("medium");
|
||||
avatars[2] = o.getString("large");
|
||||
return avatars;
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
try {
|
||||
return json.getInt("id");
|
||||
} catch (JSONException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the users profile address id
|
||||
* @return guid
|
||||
*/
|
||||
public int getGuid(){
|
||||
try {
|
||||
return json.getInt("guid");
|
||||
} catch (JSONException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
try {
|
||||
return json.getString("guid");
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDiasporaAddress(){
|
||||
try {
|
||||
return json.getString("diaspora_id");
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int getNotificationCount(){
|
||||
try {
|
||||
return json.getInt("notifications_count");
|
||||
} catch (JSONException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getUnreadMessagesCount(){
|
||||
try {
|
||||
return json.getInt("unread_messages_count");
|
||||
} catch (JSONException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getFollowingCount(){
|
||||
try {
|
||||
return json.getInt("following_count");
|
||||
} catch (JSONException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Not implemented / not needed yet:
|
||||
* boolean "admin"
|
||||
* boolean "moderator"
|
||||
* array "aspects"
|
||||
* int "id"
|
||||
* string "name"
|
||||
* boolean "selected"
|
||||
*
|
||||
* array "services"
|
||||
* ? ?
|
||||
* array "configured_services"
|
||||
* ? ?
|
||||
*
|
||||
*/
|
||||
}
|
|
@ -70,4 +70,13 @@ public class Helpers {
|
|||
" } " +
|
||||
"})();");
|
||||
}
|
||||
|
||||
public static void getUserProfile(final WebView wv) {
|
||||
wv.loadUrl("javascript: ( function() {" +
|
||||
" if (typeof gon !== 'undefined' && typeof gon.user !== 'undefined') {" +
|
||||
" var userProfile = JSON.stringify(gon.user);" +
|
||||
" AndroidBridge.setUserProfile(userProfile.toString());" +
|
||||
" } " +
|
||||
"})();");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue