use of drift.com.drift.model.Auth in project drift-sdk-android by Driftt.
the class ConversationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drift_sdk_activity_conversation);
StatusBarColorizer.setActivityColor(this);
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(downloadReceiver, filter);
textEntryEditText = findViewById(R.id.drift_sdk_conversation_activity_edit_text);
sendButtonImageView = findViewById(R.id.drift_sdk_conversation_activity_send_button);
plusButtonImageView = findViewById(R.id.drift_sdk_conversation_activity_plus_button);
recyclerView = findViewById(R.id.drift_sdk_conversation_activity_recycler_activity);
statusTextView = findViewById(R.id.drift_sdk_conversation_activity_status_view);
progressBar = findViewById(R.id.drift_sdk_conversation_activity_progress_view);
driftWelcomeMessage = findViewById(R.id.drift_sdk_conversation_activity_welcome_text_view);
driftWelcomeImageView = findViewById(R.id.drift_sdk_conversation_activity_welcome_image_view);
driftBrandTextView = findViewById(R.id.drift_sdk_conversation_activity_drift_brand_text_view);
welcomeMessageLinearLayout = findViewById(R.id.drift_sdk_conversation_activity_welcome_linear_layout);
Intent intent = getIntent();
if (intent.getExtras() != null) {
conversationId = intent.getExtras().getInt(CONVERSATION_ID, -1);
conversationType = (ConversationType) intent.getExtras().getSerializable(CONVERSATION_TYPE);
}
if (conversationId == -1 && conversationType == ConversationType.CONTINUE) {
Toast.makeText(this, "Invalid Conversation Id", Toast.LENGTH_SHORT).show();
finish();
}
Auth auth = Auth.getInstance();
if (auth != null && auth.endUser != null) {
endUserId = auth.endUser.id;
} else {
// No Auth
Toast.makeText(this, "We're sorry, an unknown error occurred", Toast.LENGTH_LONG).show();
finish();
}
sendButtonImageView.setBackgroundColor(ColorHelper.getBackgroundColor());
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle("Conversation");
}
sendButtonImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
didPressSendButton();
}
});
textEntryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
didPressSendButton();
return true;
}
return false;
}
});
textEntryEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.length() != 0) {
sendButtonImageView.setVisibility(View.VISIBLE);
} else {
sendButtonImageView.setVisibility(View.GONE);
}
}
});
AttachmentManager.getInstance().setAttachmentLoadHandle(this);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);
layoutManager.setAutoMeasureEnabled(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, recyclerView, new ClickListener() {
@Override
public void onClick(View view, int position) {
Message message = conversationAdapter.getItemAt(position);
if (message != null && message.sendStatus == Message.SendStatus.FAILED) {
resendMessage(message);
}
}
}));
conversationAdapter = new ConversationAdapter(this, MessageManager.getInstance().getMessagesForConversationId(conversationId));
recyclerView.setAdapter(conversationAdapter);
if (conversationAdapter.getItemCount() == 0) {
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.GONE);
}
}
use of drift.com.drift.model.Auth in project drift-sdk-android by Driftt.
the class ConversationListActivity method refreshData.
@Override
public void refreshData() {
super.refreshData();
networkAvailabilityBar.setVisibility(View.GONE);
final Auth auth = Auth.getInstance();
if (auth != null && auth.endUser != null) {
UserManager.getInstance().getUsers(auth.endUser.orgId, new UserManagerCallback() {
@Override
public void didLoadUsers(Boolean success) {
if (success) {
ConversationManager.getInstance().getConversationsForEndUser(auth.endUser.id, new APICallbackWrapper<ArrayList<ConversationExtra>>() {
@Override
public void onResponse(ArrayList<ConversationExtra> response) {
if (response != null) {
progressBar.setVisibility(View.GONE);
LoggerHelper.logMessage(TAG, response.toString());
if (response.isEmpty()) {
emptyState.setVisibility(View.VISIBLE);
} else {
emptyState.setVisibility(View.GONE);
}
conversationListAdapter.updateDate(response);
} else {
Alert.showAlert(ConversationListActivity.this, "Error", "Failed to load conversations", "Retry", new Runnable() {
@Override
public void run() {
refreshData();
}
});
}
}
});
} else {
LoggerHelper.logMessage(TAG, "Failed to load users");
}
}
});
}
}
use of drift.com.drift.model.Auth in project drift-sdk-android by Driftt.
the class APIAuthTokenInterceptor method intercept.
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Auth auth = Auth.getInstance();
if (auth != null && auth.getAccessToken() != null) {
HttpUrl url = request.url().newBuilder().addQueryParameter("access_token", auth.getAccessToken()).build();
request = request.newBuilder().url(url).build();
}
return chain.proceed(request);
}
use of drift.com.drift.model.Auth in project drift-sdk-android by Driftt.
the class PresentationManager method showPopupForMessage.
private void showPopupForMessage(final Message message, final int otherMessages) {
User user = UserManager.getInstance().userMap.get(message.authorId);
Auth auth = Auth.getInstance();
if (user != null) {
showPopupForMessage(user, message, otherMessages);
} else if (auth != null && auth.endUser != null && auth.endUser.orgId != null) {
UserManager.getInstance().getUsers(auth.endUser.orgId, new UserManagerCallback() {
@Override
public void didLoadUsers(Boolean success) {
User user = UserManager.getInstance().userMap.get(message.authorId);
showPopupForMessage(user, message, otherMessages);
}
});
}
}
use of drift.com.drift.model.Auth in project drift-sdk-android by Driftt.
the class ApplicationLifecycleHelper method onApplicationResumed.
void onApplicationResumed(Activity activity) {
LoggerHelper.logMessage(TAG, "Application Did Resume");
Auth auth = Auth.getInstance();
if (auth != null && auth.endUser != null && auth.endUser.id != null) {
PresentationManager.getInstance().checkForUnreadMessagesToShow(auth.endUser.orgId, auth.endUser.id);
}
}
Aggregations