Skip to content

Commit

Permalink
fix for #47
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Sep 5, 2019
1 parent f3bfee3 commit d169c64
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 143 deletions.
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@
This is a catch-all URL pattern.
Retarded Android is unable to parse URLs with fragments
-->
<data
android:host="api.tinode.co"
android:scheme="https"/>
<data android:host="web.tinode.co" android:scheme="https"/>
</intent-filter>
</activity>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/co/tinode/tindroid/FindFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ private String doSearch(String query) {
new MetaSetDesc<String, String>(query == null ? Tinode.NULL_VALUE : query, null)));
if (query != null) {
setProgressBarVisible(true);
fnd.getMeta(MsgGetMeta.sub()).thenFinally(new PromisedReply.FinalListener<ServerMessage>() {
fnd.getMeta(MsgGetMeta.sub()).thenFinally(new PromisedReply.FinalListener() {
@Override
public void onFinally() {
setProgressBarVisible(false);
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/co/tinode/tindroid/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public class LoginActivity extends AppCompatActivity {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

//private LoginFragment mLoginFragment = null;
//private SignUpFragment mSignUpFragment = null;
//private LoginSettingsFragment mSettingsFragment = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
99 changes: 65 additions & 34 deletions app/src/main/java/co/tinode/tindroid/MessageActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package co.tinode.tindroid;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.DownloadManager;
import android.app.NotificationManager;
import android.content.ActivityNotFoundException;
Expand Down Expand Up @@ -36,6 +38,7 @@
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import co.tinode.tindroid.account.Utils;
import co.tinode.tindroid.db.BaseDb;
import co.tinode.tindroid.media.VxCard;
import co.tinode.tinodesdk.ComTopic;
import co.tinode.tinodesdk.NotConnectedException;
Expand All @@ -45,6 +48,7 @@
import co.tinode.tinodesdk.Topic;
import co.tinode.tinodesdk.model.Description;
import co.tinode.tinodesdk.model.Drafty;
import co.tinode.tinodesdk.model.MsgGetMeta;
import co.tinode.tinodesdk.model.MsgServerData;
import co.tinode.tinodesdk.model.MsgServerInfo;
import co.tinode.tinodesdk.model.MsgServerPres;
Expand Down Expand Up @@ -234,6 +238,24 @@ public void onPause() {

private void topicAttach() {
setProgressIndicator(true);

PromisedReply<ServerMessage> connectionCheck = null;
if (!Cache.getTinode().isAuthenticated()) {
String uid = BaseDb.getInstance().getUid();
if (!TextUtils.isEmpty(uid)) {
AccountManager accountManager = AccountManager.get(this);
Account account = UiUtils.getSavedAccount(this, accountManager, uid);
connectionCheck = new PromisedReply<>();
UiUtils.loginWithSavedAccount(this, accountManager, account, connectionCheck);
} else {
startActivity(new Intent(this, LoginActivity.class));
finish();
return;
}
} else {
connectionCheck = new PromisedReply<>((ServerMessage) null);
}

Topic.MetaGetBuilder builder = mTopic.getMetaGetBuilder()
.withDesc()
.withSub()
Expand All @@ -244,43 +266,52 @@ private void topicAttach() {
builder = builder.withTags();
}

mTopic.subscribe(null, builder.build()).thenApply(new PromisedReply.SuccessListener<ServerMessage>() {
@Override
public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
UiUtils.setupToolbar(MessageActivity.this, mTopic.getPub(),
mTopicName, mTopic.getOnline());
showFragment(FRAGMENT_MESSAGES, null, false);
runOnUiThread(new Runnable() {
final MsgGetMeta getQuery = builder.build();

connectionCheck.thenApply(new PromisedReply.SuccessListener<ServerMessage>() {
@Override
public void run() {
setProgressIndicator(false);
MessagesFragment fragmsg = (MessagesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAGMENT_MESSAGES);
if (fragmsg != null) {
fragmsg.topicSubscribed();
public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
return mTopic.subscribe(null, getQuery);
}
}).thenApply(new PromisedReply.SuccessListener<ServerMessage>() {
@Override
public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
UiUtils.setupToolbar(MessageActivity.this, mTopic.getPub(),
mTopicName, mTopic.getOnline());
showFragment(FRAGMENT_MESSAGES, null, false);
runOnUiThread(new Runnable() {
@Override
public void run() {
MessagesFragment fragmsg = (MessagesFragment) getSupportFragmentManager()
.findFragmentByTag(FRAGMENT_MESSAGES);
if (fragmsg != null) {
fragmsg.topicSubscribed();
}
}
});
// Resume message sender and submit pending messages for processing:
// publish queued, delete marked for deletion.
mMessageSender.resume();
syncAllMessages(true);
return null;
}
}).thenCatch(new PromisedReply.FailureListener<ServerMessage>() {
@Override
public PromisedReply<ServerMessage> onFailure(Exception err) {
if (!(err instanceof NotConnectedException)) {
Log.w(TAG, "Subscribe failed", err);
if (err instanceof ServerResponseException) {
showFragment(FRAGMENT_INVALID, null, false);
}
}
return null;
}
});
// Resume message sender and submit pending messages for processing:
// publish queued, delete marked for deletion.
mMessageSender.resume();
syncAllMessages(true);
return null;
}
}, new PromisedReply.FailureListener<ServerMessage>() {
@Override
public PromisedReply<ServerMessage> onFailure(Exception err) {
setProgressIndicator(false);

if (!(err instanceof NotConnectedException)) {
Log.w(TAG, "Subscribe failed", err);
if (err instanceof ServerResponseException) {
showFragment(FRAGMENT_INVALID, null, false);
}).thenFinally(new PromisedReply.FinalListener() {
@Override
public void onFinally() {
setProgressIndicator(false);
}
}
return null;
}
});
});
}

@Override
Expand Down Expand Up @@ -441,7 +472,7 @@ public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
}
})
.thenCatch(new UiUtils.ToastFailureListener(this))
.thenFinally(new PromisedReply.FinalListener<ServerMessage>() {
.thenFinally(new PromisedReply.FinalListener() {
@Override
public void onFinally() {
// Updates message list with "delivered" or "failed" icon.
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/co/tinode/tindroid/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

// Account found, try to use it for login
UiUtils.loginWithSavedAccount(this, accountManager, account);
// Account found, try to use it for login.
UiUtils.loginWithSavedAccount(this, accountManager, account, null);
return;
}
}
Expand Down
Loading

0 comments on commit d169c64

Please sign in to comment.