Skip to content

Commit

Permalink
Merge pull request #10 from castaway2000/errors
Browse files Browse the repository at this point in the history
fix for UDID errors
  • Loading branch information
castaway2000 authored Apr 14, 2017
2 parents 837505a + 6d255da commit 5c8a618
Show file tree
Hide file tree
Showing 44 changed files with 1,410 additions and 272 deletions.
48 changes: 48 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions AndroidStudioProjects/PawPads/.gitignore

This file was deleted.

17 changes: 12 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ android {
minSdkVersion 15

targetSdkVersion 23
versionCode 25
versionCode 33

versionName "2.2.27"
versionName "2.5.2"
// Enabling multidex support.
multiDexEnabled true

Expand Down Expand Up @@ -71,21 +71,28 @@ dependencies {
compile 'com.quickblox:quickblox-android-sdk-location:2.6.1'
compile 'com.quickblox:quickblox-android-sdk-content:2.6.1'
compile 'com.quickblox:quickblox-android-sdk-customobjects:2.6.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:gridlayout-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.android.gms:play-services-identity:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.makeramen:roundedimageview:2.2.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
transitive = true;
}
compile ('io.imoji.sdk:imoji-sdk-ui:+@aar') {
transitive=true
}

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

compile 'com.github.bumptech.glide:glide:3.7.0'

}
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
android:name=".ui.chat.ChatActivity"
android:label="Chat"
android:parentActivityName=".ui.home.MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Expand Down Expand Up @@ -173,6 +172,12 @@
<meta-data
android:name="io.fabric.ApiKey"
android:value="71b41297088b136c5894241c6ffdecec047779a6" />
<activity
android:windowSoftInputMode="adjustNothing"
android:name="io.imoji.sdk.editor.ImojiEditorActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"></activity>


</application>

</manifest>
1 change: 1 addition & 0 deletions app/src/main/java/saberapplications/pawpads/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public class C {
public static final String USER_DATA_CHANGED = "user_data_changed";
public static final String UPDATE_CHAT = "update_chat";
public static final long LOCATION_PUSH_INTERVAL = 120000;
public static final String CHAT_MSG_STICKER_PROPERTY = "STICKER";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterCore;

import java.util.UUID;

import io.fabric.sdk.android.Fabric;
import io.imoji.sdk.ImojiSDK;
import saberapplications.pawpads.views.FontManager;


Expand All @@ -36,6 +39,8 @@ public void onCreate() {

FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);

ImojiSDK.getInstance().setCredentials(UUID.fromString(Util.IMOJI_SDK_CLIENT_ID), Util.IMOJI_SDK_API_TOKEN);
}

@Override
Expand Down
96 changes: 96 additions & 0 deletions app/src/main/java/saberapplications/pawpads/UserStatusHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package saberapplications.pawpads;

import android.util.Log;

import com.quickblox.users.model.QBUser;

import java.util.HashMap;
import java.util.Map;

/**
* Created by Roman Fomenko on 13.01.17.
*/

public class UserStatusHelper {
private static final long OFFLINE_TIME = 600000; // 10 min
private static final long AWAY_TIME = 300000; // 5 min
private static final int USER_OFFLINE = 1;
private static final int USER_AWAY = 2;
public static final int USER_ONLINE = 3;
private static Map<Integer, Integer> mStatusUserList = new HashMap<>();
private static Map<Integer, Long> mStatusByNewMessageChangedTimeList = new HashMap<>();

public static int getUserStatus(QBUser user) {
int userStatusByLastRequest = getUserStatusByLastRequestTime(user);
if( !mStatusUserList.containsKey(user.getId())) {
Log.d("UserStatusHelper", user.getId() + " " + userStatusByLastRequest);
mStatusUserList.put(user.getId(), userStatusByLastRequest);
mStatusByNewMessageChangedTimeList.put(user.getId(), 0L);
return userStatusByLastRequest;
} else {
int existStatus = mStatusUserList.get(user.getId());
long lastChangedStatusTime = mStatusByNewMessageChangedTimeList.get(user.getId());
long currentTime = System.currentTimeMillis();
long userLastRequestAtTime = user.getLastRequestAt().getTime();
if(lastChangedStatusTime == 0L ||
(currentTime - lastChangedStatusTime) > (currentTime - userLastRequestAtTime)) {
Log.d("UserStatusHelper", "lastChangedStatusTime is 0 or was a long time ago");
mStatusUserList.put(user.getId(), userStatusByLastRequest);
return userStatusByLastRequest;
} else {
if (existStatus >= userStatusByLastRequest) {
Log.d("UserStatusHelper", user.getId() + " exist-" + existStatus);
return getCheckedExistStatus(user);
} else {
mStatusUserList.put(user.getId(), userStatusByLastRequest);
Log.d("UserStatusHelper", user.getId() + " byreq-" + userStatusByLastRequest);
return userStatusByLastRequest;
}
}
}
}

private static int getUserStatusByLastRequestTime(QBUser user) {
long currentTime = System.currentTimeMillis();
long userLastRequestAtTime = user.getLastRequestAt().getTime();
Log.d("UserStatusHelper", "getLastRequestAt = " + user.getLastRequestAt().getTime() +
" currentTime = " + currentTime +
" userLastRequestAtTime = " + (currentTime - userLastRequestAtTime));

if ((currentTime - userLastRequestAtTime) > OFFLINE_TIME) {
// user is offline now
return USER_OFFLINE;
} else if ((currentTime - userLastRequestAtTime) > AWAY_TIME) {
// user is away now
return USER_AWAY;
} else {
// else online
return USER_ONLINE;
}
}

private static int getCheckedExistStatus(QBUser user) {
int checkedStatus;
long lastChangedStatusTime = mStatusByNewMessageChangedTimeList.get(user.getId());
long currentTime = System.currentTimeMillis();

if ((currentTime - lastChangedStatusTime) > OFFLINE_TIME) {
// user is offline now
checkedStatus = USER_OFFLINE;
} else if ((currentTime - lastChangedStatusTime) > AWAY_TIME) {
// user is away now
checkedStatus = USER_AWAY;
} else {
// else online
checkedStatus = USER_ONLINE;
}
mStatusUserList.put(user.getId(), checkedStatus);
return checkedStatus;
}

public static void setUserStatusByNewMessage(int userId) {
Log.d("UserStatusHelper", " new status for user " + userId);
mStatusUserList.put(userId, USER_ONLINE);
mStatusByNewMessageChangedTimeList.put(userId, System.currentTimeMillis());
}
}
17 changes: 13 additions & 4 deletions app/src/main/java/saberapplications/pawpads/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ public class Util {
public static final String QB_AUTH_SECRET = "PUT YOURS HERE";
public static final String QB_ACCOUNT_KEY = "PUT YOURS HERE";

//quickblox ID
public static final String QB_APPID = "PUT YOURS HERE";
public static final String QB_AUTH_KEY = "PUT YOURS HERE";
public static final String QB_AUTH_SECRET = "PUT YOURS HERE";
public static final String QB_ACCOUNT_KEY = "PUT YOURS HERE";

public static final String STICKERS_API_KEY = "PUT YOURS HERE";
public static final String STICKERS_API_KEY = "PUT YOUR IMOJI KEY HERE";
public static final String IMOJI_SDK_CLIENT_ID = "PUT YOUR IMOJI CLIENT ID HERE";
public static final String IMOJI_SDK_API_TOKEN = "PUT YOUR IMOJI API TOKEN HERE";

public static String ACCURACY;
public static int RANGE;
Expand All @@ -62,7 +69,7 @@ public static void onError(List<String> errors, Context context) {
for (String error : errors) {
msg = msg + error + "\n";
}
showAlert(context,msg);
showAlert(context, msg);
}

public static void onError(Exception e, Context context) {
Expand All @@ -72,8 +79,10 @@ public static void onError(Exception e, Context context) {

public static void onError(QBResponseException e, Context context) {
Crashlytics.getInstance().logException(e);
showAlert(context,e.getLocalizedMessage());

String message = e.getLocalizedMessage();
if(!message.contains("Subscription with such UDID already exists")){
showAlert(context, e.getLocalizedMessage());
}
}
public static void onError(String error, Context context) {
showAlert(context,error);
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/saberapplications/pawpads/ui/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import saberapplications.pawpads.C;
import saberapplications.pawpads.R;
import saberapplications.pawpads.UserStatusHelper;
import saberapplications.pawpads.Util;
import saberapplications.pawpads.service.UserLocationService;
import saberapplications.pawpads.ui.chat.ChatActivity;
Expand Down Expand Up @@ -72,8 +73,15 @@ public void chatCreated(QBPrivateChat qbPrivateChat, final boolean createdLocall
if (!createdLocally) {
qbPrivateChat.addMessageListener(new QBMessageListener<QBPrivateChat>() {
@Override
public void processMessage(QBPrivateChat qbPrivateChat, final QBChatMessage qbChatMessage) {
onChatMessage(qbPrivateChat, qbChatMessage);
public void processMessage(final QBPrivateChat qbPrivateChat, final QBChatMessage qbChatMessage) {
BaseActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
onChatMessage(qbPrivateChat, qbChatMessage);
UserStatusHelper.setUserStatusByNewMessage(qbChatMessage.getSenderId());
}
});

}

@Override
Expand Down Expand Up @@ -338,7 +346,7 @@ public boolean isLoggedIn() {
}

public void onChatMessage(QBPrivateChat qbPrivateChat, final QBChatMessage qbChatMessage) {
if (Util.IM_ALERT == true) {
if (Util.IM_ALERT) {
new AlertDialog.Builder(BaseActivity.this)
.setTitle(R.string.new_chat_message)
.setMessage(qbChatMessage.getBody())
Expand All @@ -347,7 +355,7 @@ public void onChatMessage(QBPrivateChat qbPrivateChat, final QBChatMessage qbCha
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(BaseActivity.this, ChatActivity.class);
intent.putExtra(ChatActivity.DIALOG_ID, qbChatMessage.getDialogId().toString());
intent.putExtra(ChatActivity.RECIPIENT_ID, qbChatMessage.getSenderId().toString());
intent.putExtra(ChatActivity.RECIPIENT_ID, qbChatMessage.getSenderId());
startActivity(intent);
}
})
Expand Down
Loading

0 comments on commit 5c8a618

Please sign in to comment.