Added a dialog to choose between categories to pick files from

This commit is contained in:
Lyndon
2017-10-30 21:41:52 +01:00
parent c9c3702c7a
commit d4300a025c
45 changed files with 183 additions and 189 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@@ -19,4 +19,7 @@ public interface AppPrefsConstants {
String IS_EMPLOYEE = "is_employee"; String IS_EMPLOYEE = "is_employee";
String SHOW_LOGIN_AGAIN = "show_login_again"; String SHOW_LOGIN_AGAIN = "show_login_again";
String LAST_ACCOUNT_NO = "last_account_no"; String LAST_ACCOUNT_NO = "last_account_no";
String USER_PASSWORD = "user_password";
String USER_NAME = "user_name";
} }

View File

@@ -1,4 +1,14 @@
package de.beyondsoft.ownchat.data.events; package de.beyondsoft.ownchat.data.events;
public class LogoutDirectlyEvent { public class LogoutDirectlyEvent {
private boolean mClearAllPrefs;
public boolean getClearAllPrefs() {
return mClearAllPrefs;
}
public LogoutDirectlyEvent(boolean clearAllPrefs) {
mClearAllPrefs = clearAllPrefs;
}
} }

View File

@@ -6,7 +6,6 @@ import com.google.firebase.messaging.RemoteMessage;
import de.beyondsoft.ownchat.R; import de.beyondsoft.ownchat.R;
import de.beyondsoft.ownchat.data.AppPrefsConstants; import de.beyondsoft.ownchat.data.AppPrefsConstants;
import de.beyondsoft.ownchat.data.api.common.ErrorHandlingResponseConverter; import de.beyondsoft.ownchat.data.api.common.ErrorHandlingResponseConverter;
import de.beyondsoft.ownchat.data.api.responses.MessageResponse;
import de.beyondsoft.ownchat.data.api.services.ChatService; import de.beyondsoft.ownchat.data.api.services.ChatService;
import de.beyondsoft.ownchat.data.prefs.LongPreference; import de.beyondsoft.ownchat.data.prefs.LongPreference;
import de.beyondsoft.ownchat.data.repository.GroupRealmRepository; import de.beyondsoft.ownchat.data.repository.GroupRealmRepository;
@@ -18,10 +17,8 @@ import de.beyondsoft.ownchat.model.Group;
import de.beyondsoft.ownchat.model.Message; import de.beyondsoft.ownchat.model.Message;
import de.beyondsoft.ownchat.page.main.MainActivity; import de.beyondsoft.ownchat.page.main.MainActivity;
import de.beyondsoft.ownchat.utils.Constants; import de.beyondsoft.ownchat.utils.Constants;
import de.beyondsoft.ownchat.utils.LoggedOutUtils;
import de.beyondsoft.ownchat.utils.rx.RxUtils; import de.beyondsoft.ownchat.utils.rx.RxUtils;
import rx.Observable; import rx.Observable;
import rx.functions.Func1;
import android.app.Activity; import android.app.Activity;
import android.app.Notification; import android.app.Notification;
@@ -75,16 +72,13 @@ public class HandleMessagesService extends FirebaseMessagingService {
@Named(AppPrefsConstants.USER_ID) @Named(AppPrefsConstants.USER_ID)
LongPreference mUserIdReference; LongPreference mUserIdReference;
@Inject
LoggedOutUtils mLoggedOutUtils;
@Override @Override
public void onMessageReceived(RemoteMessage remoteMessage) { public void onMessageReceived(RemoteMessage remoteMessage) {
InjectionHelper.getMessagingComponent(this).inject(HandleMessagesService.this); InjectionHelper.getMessagingComponent(this).inject(HandleMessagesService.this);
if (mLoggedOutUtils.checkLoggedOutPrefs()) { // if (mLoggedOutUtils.checkLoggedOutPrefs()) {
return; // return;
} // }
customizeNotification(remoteMessage.getData()); customizeNotification(remoteMessage.getData());
} }
@@ -109,12 +103,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
mChatService.getMessage(messageId) mChatService.getMessage(messageId)
.compose(RxUtils.provideDefaultTransformer()) .compose(RxUtils.provideDefaultTransformer())
.flatMap(new ErrorHandlingResponseConverter<>()) .flatMap(new ErrorHandlingResponseConverter<>())
.flatMap(new Func1<MessageResponse, Observable<Message>>() { .flatMap(messageResponse -> Observable.just(messageResponse.response.message))
@Override
public Observable<Message> call(MessageResponse messageResponse) {
return Observable.just(messageResponse.response.message);
}
})
.subscribe(this::getMessageSuccess, this::getMessageError); .subscribe(this::getMessageSuccess, this::getMessageError);
} }

View File

@@ -8,6 +8,7 @@ import com.securepreferences.SecurePreferences;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.provider.Settings;
import javax.inject.Named; import javax.inject.Named;
@@ -54,6 +55,20 @@ public class AppPrefsModule {
return new BooleanPreference(sharedPreferences, AppPrefsConstants.SAVE_PASSWORD); return new BooleanPreference(sharedPreferences, AppPrefsConstants.SAVE_PASSWORD);
} }
@Provides
@ApplicationScope
@Named(AppPrefsConstants.USER_NAME)
StringPreference provideUserName(@AppPrefs SecurePreferences sharedPreferences) {
return new StringPreference(sharedPreferences, AppPrefsConstants.USER_NAME);
}
@Provides
@ApplicationScope
@Named(AppPrefsConstants.USER_PASSWORD)
StringPreference providePassword(@AppPrefs SecurePreferences sharedPreferences) {
return new StringPreference(sharedPreferences, AppPrefsConstants.USER_PASSWORD);
}
@Provides @Provides
@ApplicationScope @ApplicationScope
@Named(AppPrefsConstants.CHAT_CODE) @Named(AppPrefsConstants.CHAT_CODE)

View File

@@ -88,6 +88,12 @@ public interface ApplicationComponent {
@Named(AppPrefsConstants.SHOW_LOGIN_AGAIN) @Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
BooleanPreference provideShowLoginAgain(); BooleanPreference provideShowLoginAgain();
@Named(AppPrefsConstants.USER_NAME)
StringPreference provideUserName();
@Named(AppPrefsConstants.USER_PASSWORD)
StringPreference providePassword();
NotificationManager provideNotificationManager(); NotificationManager provideNotificationManager();
GroupRealmRepository provideGroupRealmRepository(); GroupRealmRepository provideGroupRealmRepository();

View File

@@ -32,7 +32,7 @@ public class FilePickerConst {
public final static int MEDIA_TYPE_IMAGE=1; public final static int MEDIA_TYPE_IMAGE=1;
public final static int MEDIA_TYPE_VIDEO=3; public final static int MEDIA_TYPE_VIDEO=3;
public enum FILE_TYPE{ public enum FILE_TYPE {
PDF, PDF,
WORD, WORD,
EXCEL, EXCEL,

View File

@@ -73,7 +73,7 @@ public class FolderGridAdapter extends SelectableAdapter<FolderGridAdapter.Image
if(AndroidLifecycleUtils.canLoadImage(holder.imageView.getContext())) { if(AndroidLifecycleUtils.canLoadImage(holder.imageView.getContext())) {
glide.load(new File(photoDirectory.getCoverPath())) glide.load(new File(photoDirectory.getCoverPath()))
.override(imageSize, imageSize) .override(imageSize, imageSize)
.placeholder(R.drawable.document) .fallback(R.drawable.document)
.thumbnail(0.5f) .thumbnail(0.5f)
.into(holder.imageView); .into(holder.imageView);
} }
@@ -84,22 +84,23 @@ public class FolderGridAdapter extends SelectableAdapter<FolderGridAdapter.Image
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if(folderGridAdapterListener!=null) if(folderGridAdapterListener!=null) {
folderGridAdapterListener.onFolderClicked(photoDirectory); folderGridAdapterListener.onFolderClicked(photoDirectory);
}
} }
}); });
holder.bottomOverlay.setVisibility(View.VISIBLE); holder.bottomOverlay.setVisibility(View.VISIBLE);
} }
else else
{ {
holder.imageView.setImageResource(PickerManager.getInstance().getCameraDrawable()); holder.imageView.setImageResource(PickerManager.getInstance().getCameraDrawable());
holder.itemView.setOnClickListener(new View.OnClickListener() { holder.itemView.setOnClickListener(view -> {
@Override if(folderGridAdapterListener!=null) {
public void onClick(View view) { folderGridAdapterListener.onCameraClicked();
if(folderGridAdapterListener!=null)
folderGridAdapterListener.onCameraClicked();
} }
}); });
holder.bottomOverlay.setVisibility(View.GONE); holder.bottomOverlay.setVisibility(View.GONE);
} }
} }
@@ -124,18 +125,18 @@ public class FolderGridAdapter extends SelectableAdapter<FolderGridAdapter.Image
this.folderGridAdapterListener = onClickListener; this.folderGridAdapterListener = onClickListener;
} }
public static class ImageViewHolder extends RecyclerView.ViewHolder { static class ImageViewHolder extends RecyclerView.ViewHolder {
ImageView imageView; ImageView imageView;
TextView folderTitle; TextView folderTitle;
TextView folderCount; TextView folderCount;
View bottomOverlay; View bottomOverlay;
View selectBg; View selectBg;
public ImageViewHolder(View itemView) { ImageViewHolder(View itemView) {
super(itemView); super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.iv_photo); imageView = itemView.findViewById(R.id.iv_photo);
folderTitle = (TextView) itemView.findViewById(R.id.folder_title); folderTitle = itemView.findViewById(R.id.folder_title);
folderCount = (TextView) itemView.findViewById(R.id.folder_count); folderCount = itemView.findViewById(R.id.folder_count);
bottomOverlay = itemView.findViewById(R.id.bottomOverlay); bottomOverlay = itemView.findViewById(R.id.bottomOverlay);
selectBg = itemView.findViewById(R.id.transparent_bg); selectBg = itemView.findViewById(R.id.transparent_bg);
} }

View File

@@ -1,6 +1,7 @@
package de.beyondsoft.ownchat.filepicker.utils; package de.beyondsoft.ownchat.filepicker.utils;
import android.database.DataSetObserver; import android.database.DataSetObserver;
import android.graphics.Color;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
@@ -15,6 +16,8 @@ import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import de.beyondsoft.ownchat.R;
/** /**
* Created by Lyndon on 26-Oct-2017. * Created by Lyndon on 26-Oct-2017.
*/ */
@@ -43,6 +46,7 @@ public class TabLayoutHelper {
}/**/ }/**/
mTabLayout = tabLayout; mTabLayout = tabLayout;
mTabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FF5E00"));
mViewPager = viewPager; mViewPager = viewPager;
mInternalDataSetObserver = new DataSetObserver() { mInternalDataSetObserver = new DataSetObserver() {
@@ -71,12 +75,7 @@ public class TabLayoutHelper {
mInternalTabLayoutOnPageChangeListener = new FixedTabLayoutOnPageChangeListener(mTabLayout); mInternalTabLayoutOnPageChangeListener = new FixedTabLayoutOnPageChangeListener(mTabLayout);
mInternalOnAdapterChangeListener = new ViewPager.OnAdapterChangeListener() { mInternalOnAdapterChangeListener = (viewPager1, oldAdapter, newAdapter) -> handleOnAdapterChanged(viewPager1, oldAdapter, newAdapter);
@Override
public void onAdapterChanged(@NonNull ViewPager viewPager, @Nullable PagerAdapter oldAdapter, @Nullable PagerAdapter newAdapter) {
handleOnAdapterChanged(viewPager, oldAdapter, newAdapter);
}
};
setupWithViewPager(mTabLayout, mViewPager); setupWithViewPager(mTabLayout, mViewPager);
} }

View File

@@ -20,6 +20,7 @@ import de.beyondsoft.ownchat.utils.Constants;
import de.beyondsoft.ownchat.utils.EndlessScrollListener; import de.beyondsoft.ownchat.utils.EndlessScrollListener;
import de.beyondsoft.ownchat.utils.FileUtils; import de.beyondsoft.ownchat.utils.FileUtils;
import de.beyondsoft.ownchat.utils.SystemUtils; import de.beyondsoft.ownchat.utils.SystemUtils;
import de.beyondsoft.ownchat.utils.Utils;
import de.beyondsoft.ownchat.utils.ui.EmptyLayout; import de.beyondsoft.ownchat.utils.ui.EmptyLayout;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
@@ -74,7 +75,8 @@ import okhttp3.MediaType;
abstract class BaseChatActivity extends RuntimePermissionActivity implements ChatView, BaseChatAdapter.MessageClickListener, LogoutNavigation { abstract class BaseChatActivity extends RuntimePermissionActivity implements ChatView, BaseChatAdapter.MessageClickListener, LogoutNavigation {
private final static int STORAGE_REQUEST_CODE = 9999; private final static int STORAGE_REQUEST_CODE = 9999;
private final static int SELECT_FILE = 233; private final static int SELECT_IMAGE_FILE = 233;
private final static int SELECT_DOC_FILE = 234;
private final static int CONFIRM_FILE = 666; private final static int CONFIRM_FILE = 666;
private final static int VISIBLE_THRESHOLD = 25; private final static int VISIBLE_THRESHOLD = 25;
protected final static String MESSAGE_ARG = "message_arg"; protected final static String MESSAGE_ARG = "message_arg";
@@ -273,36 +275,23 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
} }
private void selectFile(int requestCode) { private void selectFile(int requestCode) {
// Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
//
// intent.addCategory(Intent.CATEGORY_OPENABLE);
//
// intent.setType("*/*");
// intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//
// startActivityForResult(Intent.createChooser(intent, getResources().getString(R.string.chat_select_file)), SELECT_FILE);
// TODO: show attachment type dialog first // TODO: show attachment type dialog first
final String[] zipFileTypes = {".zip", ".rar", ".7zip"}; final String[] zipFileTypes = {".zip", ".rar", ".7zip"};
final String[] pdfFileTypes = {".pdf"}; final String[] pdfFileTypes = {".pdf"};
final String[] docFileTypes = {".txt", ".doc", ".xls", ".docx", ".xlsx", ".odt"};
final Dialog dialog = new Dialog(this); final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.file_chooser_dialog); dialog.setContentView(R.layout.file_chooser_dialog);
ImageView attachFromGalleryImageView = dialog.findViewById(R.id.attachFromGalleryBtn); ImageView attachFromGalleryImageView = dialog.findViewById(R.id.attachFromGalleryBtn);
ImageView attachDocumentImageView = dialog.findViewById(R.id.attachDocumentBtn); ImageView attachDocumentImageView = dialog.findViewById(R.id.attachDocumentBtn);
ImageView attachAudioImageView = dialog.findViewById(R.id.attachAudioBtn);
attachAudioImageView.setOnClickListener(v -> {
dialog.dismiss();
});
attachDocumentImageView.setOnClickListener(v -> { attachDocumentImageView.setOnClickListener(v -> {
FilePickerBuilder.getInstance().setMaxCount(1) FilePickerBuilder.getInstance().setMaxCount(1)
.addFileSupport("ZIP", zipFileTypes) .addFileSupport("ZIP", zipFileTypes)
.addFileSupport("PDF", pdfFileTypes) .addFileSupport("PDF", pdfFileTypes)
.addFileSupport("DOC", docFileTypes)
.enableDocSupport(false) .enableDocSupport(false)
.withOrientation(Orientation.PORTRAIT_ONLY) .withOrientation(Orientation.PORTRAIT_ONLY)
.pickFile(this); .pickFile(this);
@@ -343,15 +332,16 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
return; return;
} }
if (requestCode == SELECT_FILE) { if (requestCode == SELECT_IMAGE_FILE || requestCode == SELECT_DOC_FILE) {
// TODO: support documents too (FilePickerConst.KEY_SELECTED_DOCS) String filePath = data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA) != null ?
final Uri uri = Uri.fromFile(new File(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA) != null ?
data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA).get(0) : data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA).get(0) :
data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS).get(0))); data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS).get(0);
final Uri uri = Uri.fromFile(new File(filePath));
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19) {
final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
// Check for the freshest data.
try { try {
//noinspection WrongConstant //noinspection WrongConstant
getContentResolver().takePersistableUriPermission(uri, takeFlags); getContentResolver().takePersistableUriPermission(uri, takeFlags);
@@ -365,7 +355,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
} }
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(Constants.FILENAME, data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA).get(0)); bundle.putString(Constants.FILENAME, filePath);
Intent intent = new Intent(this, FileConfirmationActivity.class); Intent intent = new Intent(this, FileConfirmationActivity.class);
intent.putExtras(bundle); intent.putExtras(bundle);
@@ -389,7 +379,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
@Override @Override
public void logoutDirectly(boolean clearAllPrefs) { public void logoutDirectly(boolean clearAllPrefs) {
EventBus.getDefault().post(new LogoutDirectlyEvent()); EventBus.getDefault().post(new LogoutDirectlyEvent(clearAllPrefs));
finish(); finish();
} }
@@ -500,14 +490,17 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
@Override @Override
protected void onDestroy() { protected void onDestroy() {
mChatOpenedPref.set(false); mChatOpenedPref.set(false);
if (mEndlessScrollListener != null) { if (mEndlessScrollListener != null) {
mRecyclerView.removeOnScrollListener(mEndlessScrollListener); mRecyclerView.removeOnScrollListener(mEndlessScrollListener);
} }
getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(mKeyboardListener); getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(mKeyboardListener);
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
InjectionHelper.destroyChatComponent(); InjectionHelper.destroyChatComponent();
mRecyclerView.setAdapter(null); mRecyclerView.setAdapter(null);
mEmptyLayout.setOnTryAgainClickListener(null); mEmptyLayout.setOnTryAgainClickListener(null);
super.onDestroy(); super.onDestroy();
} }

View File

@@ -87,10 +87,10 @@ public class FileConfirmationActivity extends AppCompatActivity implements FileC
mSelectedUri = Uri.parse(fileUri); mSelectedUri = Uri.parse(fileUri);
// getFile(mSelectedUri).getPath()
Glide.with(this) Glide.with(this)
.load(fileUri) .load(fileUri)
.dontAnimate() .dontAnimate()
.placeholder(R.drawable.document)
.diskCacheStrategy(DiskCacheStrategy.ALL) .diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new GlideDrawableImageViewTarget(mFileImageView)); .into(new GlideDrawableImageViewTarget(mFileImageView));

View File

@@ -22,6 +22,8 @@ import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
@@ -135,6 +137,7 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
InjectionHelper.destroyLoginComponent(); InjectionHelper.destroyLoginComponent();
InjectionHelper.getLoginComponent(this).inject(this); InjectionHelper.getLoginComponent(this).inject(this);
mLoginPresenter.attachView(this); mLoginPresenter.attachView(this);
mCallback.tryToLogin(mUsernameEditText.getText().toString().trim(), mPasswordEditText.getText().toString(), mChatCodeEditText.getText().toString().trim()); mCallback.tryToLogin(mUsernameEditText.getText().toString().trim(), mPasswordEditText.getText().toString(), mChatCodeEditText.getText().toString().trim());
} }
@@ -166,6 +169,12 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
mChatCodeEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.CHAT_CODE, null))); mChatCodeEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.CHAT_CODE, null)));
} else if (key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.ACCOUNT_NO))) { } else if (key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.ACCOUNT_NO))) {
mAccountEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.ACCOUNT_NO, null))); mAccountEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.ACCOUNT_NO, null)));
} else if(key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.USER_NAME))) {
mUsernameEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.USER_NAME, null)));
} else if(key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.USER_PASSWORD))) {
mPasswordEditText.setText(String.valueOf(mSecuredPrefs.getString(AppPrefsConstants.USER_PASSWORD, null)));
} else if(key.equals(SecurePreferences.hashPrefKey(AppPrefsConstants.SAVE_PASSWORD))) {
mSavePasswordCheckbox.setChecked(mSecuredPrefs.getBoolean(AppPrefsConstants.SAVE_PASSWORD, false));
} }
} }
} }

View File

@@ -80,6 +80,14 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Named(AppPrefsConstants.CHAT_CODE) @Named(AppPrefsConstants.CHAT_CODE)
StringPreference mChatCodePreference; StringPreference mChatCodePreference;
@Inject
@Named(AppPrefsConstants.USER_PASSWORD)
StringPreference mPasswordPreference;
@Inject
@Named(AppPrefsConstants.USER_NAME)
StringPreference mUserNamePreference;
@Inject @Inject
@Named(AppPrefsConstants.SAVE_PASSWORD) @Named(AppPrefsConstants.SAVE_PASSWORD)
BooleanPreference mSavePasswordPreference; BooleanPreference mSavePasswordPreference;
@@ -183,7 +191,17 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
Subscription subscription = mLoginService.loginWithChatCode(username, password, chatCode) Subscription subscription = mLoginService.loginWithChatCode(username, password, chatCode)
.compose(RxUtils.provideDefaultTransformer()) .compose(RxUtils.provideDefaultTransformer())
.flatMap(new ErrorHandlingResponseConverter<>()) .flatMap(new ErrorHandlingResponseConverter<>())
.map(loginResponse -> loginResponse.response.user) .map(loginResponse -> {
if(mSavePasswordPreference.get()) {
mUserNamePreference.set(username);
mPasswordPreference.set(password);
} else {
mUserNamePreference.delete();
mPasswordPreference.delete();
}
return loginResponse.response.user;
})
.subscribe(this::loginSuccess, this::loginError); .subscribe(this::loginSuccess, this::loginError);
addSubscription(subscription); addSubscription(subscription);
@@ -242,8 +260,7 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
String lastAccountNumber = mLastAccountNumberPreference.get(); String lastAccountNumber = mLastAccountNumberPreference.get();
if(!accountNumber.equals(lastAccountNumber)) { if(!accountNumber.equals(lastAccountNumber)) {
//deleteData(true); deleteDataOnCustomerIdChange();
deleteData2();
} }
mIsEmployee.set(user.isEmployee); mIsEmployee.set(user.isEmployee);
@@ -253,6 +270,7 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
mAvatarPreference.set(user.avatar); mAvatarPreference.set(user.avatar);
mPhoneNumberPreference.set(user.mobile); mPhoneNumberPreference.set(user.mobile);
mProfileNamePreference.set(user.firstName.concat(" ").concat(user.lastName)); mProfileNamePreference.set(user.firstName.concat(" ").concat(user.lastName));
getView().loginSuccessful(); getView().loginSuccessful();
} }
@@ -329,32 +347,29 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
getView().showLoading(); getView().showLoading();
Subscription subscription = mLoginService.getServiceType("1", customerId) Subscription subscription = mLoginService.getServiceType("1", customerId)
.flatMap(new Func1<JsonObject, Observable<Boolean>>() { .flatMap(response -> {
@Override JsonObject serviceObject = response.getAsJsonObject();
public Observable<Boolean> call(JsonObject response) {
JsonObject serviceObject = response.getAsJsonObject();
if (serviceObject.has("Status") if (serviceObject.has("Status")
&& !TextUtils.isEmpty(serviceObject.get("Status").getAsString()) && !TextUtils.isEmpty(serviceObject.get("Status").getAsString())
&& serviceObject.has("URL") && serviceObject.has("URL")
&& !TextUtils.isEmpty(serviceObject.get("URL").getAsString())) { && !TextUtils.isEmpty(serviceObject.get("URL").getAsString())) {
String serverName = serviceObject.get("URL").getAsString(); String serverName = serviceObject.get("URL").getAsString();
if (!serverName.startsWith("https")) { if (!serverName.startsWith("https")) {
serverName = "https://" + serverName + "/"; serverName = "https://" + serverName + "/";
}
mApiEndpointPreference.set(serverName);
return Observable.just(true);
} else if(serviceObject.has("Status") && !TextUtils.isEmpty(serviceObject.get("Status").getAsString())) {
mStatus = serviceObject.get("Status").getAsInt();
} }
return Observable.just(false); mApiEndpointPreference.set(serverName);
return Observable.just(true);
} else if(serviceObject.has("Status") && !TextUtils.isEmpty(serviceObject.get("Status").getAsString())) {
mStatus = serviceObject.get("Status").getAsInt();
} }
return Observable.just(false);
}) })
.compose(RxUtils.provideDefaultTransformer()) .compose(RxUtils.provideDefaultTransformer())
.subscribe(this::checkTypeAndCustomerIdSuccessful, this::checkTypeAndCustomerIdError); .subscribe(this::checkTypeAndCustomerIdSuccessful, this::checkTypeAndCustomerIdError);
@@ -392,17 +407,14 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
getView().showLoading(); getView().showLoading();
Subscription subscription = mLoginService.getUploadMaxSize() Subscription subscription = mLoginService.getUploadMaxSize()
.flatMap(new Func1<JsonObject, Observable<Integer>>() { .flatMap(response -> {
@Override JsonObject maxSizeObject = response.getAsJsonObject();
public Observable<Integer> call(JsonObject response) {
JsonObject maxSizeObject = response.getAsJsonObject();
if(maxSizeObject.has("file_upload_max_size")) { if(maxSizeObject.has("file_upload_max_size")) {
mUploadMaxSizePreference.set(maxSizeObject.get("file_upload_max_size").getAsLong()); mUploadMaxSizePreference.set(maxSizeObject.get("file_upload_max_size").getAsLong());
}
return Observable.just(0);
} }
return Observable.just(0);
}) })
.compose(RxUtils.provideDefaultTransformer()) .compose(RxUtils.provideDefaultTransformer())
.subscribe(this::retrieveUploadMaxSizeSuccessful, this::retrieveUploadMaxSizeError); .subscribe(this::retrieveUploadMaxSizeSuccessful, this::retrieveUploadMaxSizeError);
@@ -480,6 +492,7 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Override @Override
public void tryToLogout(String deviceId, MainNavigation mainNavigation) { public void tryToLogout(String deviceId, MainNavigation mainNavigation) {
// TODO: what if the password save checkbox is set and the user logs out?
if (mSavePasswordPreference.get()) { if (mSavePasswordPreference.get()) {
return; return;
} }
@@ -592,13 +605,7 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
} }
} }
private void deleteData2() { private void deleteDataOnCustomerIdChange() {
// Observable.create(subscriber -> mGlide.clearDiskCache())
// .subscribeOn(Schedulers.io())
// .subscribe();
//
// mGlide.clearMemory();
File dir = mContext.getExternalFilesDir(null); File dir = mContext.getExternalFilesDir(null);
if (dir != null) { if (dir != null) {

View File

@@ -38,7 +38,6 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
@@ -267,7 +266,7 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
public void onLogoutDirectlyEvent(LogoutDirectlyEvent logoutDirectlyEvent) { public void onLogoutDirectlyEvent(LogoutDirectlyEvent logoutDirectlyEvent) {
logoutDirectly(true); logoutDirectly(logoutDirectlyEvent.getClearAllPrefs());
} }
@Override @Override
@@ -275,11 +274,6 @@ public class MainActivity extends AppCompatActivity implements MainNavigation, L
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
mChatOpenedPref.set(false); mChatOpenedPref.set(false);
if (!mLogoutClicked && getIntent().getBooleanExtra(LOGOUT, true)) {
mLoginPresenter.tryToLogout(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID), this);
}
getIntent().removeExtra(LOGOUT);
InjectionHelper.destroyMainComponents(); InjectionHelper.destroyMainComponents();
super.onDestroy(); super.onDestroy();
} }

View File

@@ -25,6 +25,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -37,6 +38,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.OnTextChanged; import butterknife.OnTextChanged;
import de.beyondsoft.ownchat.utils.ui.ViewUtils;
import de.hdodenhof.circleimageview.CircleImageView; import de.hdodenhof.circleimageview.CircleImageView;
/** /**
@@ -61,6 +63,9 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
@BindView(R.id.profile_update_button) @BindView(R.id.profile_update_button)
Button mUpdateProfileButton; Button mUpdateProfileButton;
@BindView(R.id.profile_avatar_progress_bar)
ProgressBar mProgressBar;
@Inject @Inject
@Named(AppPrefsConstants.NAME) @Named(AppPrefsConstants.NAME)
StringPreference mProfileNamePreference; StringPreference mProfileNamePreference;
@@ -97,8 +102,11 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
getActivity().setTitle(R.string.title_profile); getActivity().setTitle(R.string.title_profile);
Glide.with(getActivity()) Glide.with(getActivity())
.load(mAvatarPreference.get()) .load(mAvatarPreference.get())
.placeholder(R.drawable.avatar)
.into(mAvatarImageview); .into(mAvatarImageview);
ViewUtils.setProgressBarColor(mProgressBar, R.color.colorDefault);
if (!TextUtils.isEmpty(mPhoneNumberPreference.get())) { if (!TextUtils.isEmpty(mPhoneNumberPreference.get())) {
mPhoneNumberEditText.setText(mPhoneNumberPreference.get()); mPhoneNumberEditText.setText(mPhoneNumberPreference.get());
} }
@@ -145,6 +153,7 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
mProfilePresenter.attachView(this); mProfilePresenter.attachView(this);
} }
mProgressBar.setVisibility(View.VISIBLE);
mCallback.uploadImage(uri); mCallback.uploadImage(uri);
} }
} }
@@ -180,10 +189,13 @@ public class ProfileFragment extends RuntimePermissionBaseFragment implements Pr
@Override @Override
public void refreshImage(String imageUrl) { public void refreshImage(String imageUrl) {
mProgressBar.setVisibility(View.GONE);
Glide.with(getContext()) Glide.with(getContext())
.load(imageUrl) .load(imageUrl)
.error(R.drawable.avatar) .error(R.drawable.avatar)
.into(mAvatarImageview); .into(mAvatarImageview);
mAvatarPreference.set(imageUrl); mAvatarPreference.set(imageUrl);
} }

View File

@@ -47,9 +47,7 @@ public class AppStoppedService extends Service {
@Override @Override
public void onTaskRemoved(Intent rootIntent) { public void onTaskRemoved(Intent rootIntent) {
mAppKilledPreference.set(true); mAppKilledPreference.set(true);
if (!mSavedPasswordPref.get()) {
mNotificationManager.cancelAll();
}
stopSelf(); stopSelf();
} }
} }

View File

@@ -1,52 +0,0 @@
package de.beyondsoft.ownchat.utils;
import de.beyondsoft.ownchat.data.AppPrefsConstants;
import de.beyondsoft.ownchat.data.prefs.BooleanPreference;
import de.beyondsoft.ownchat.di.scopes.ActivityScope;
import de.beyondsoft.ownchat.page.login.LoginPresenter;
import android.app.NotificationManager;
import android.content.Context;
import android.provider.Settings;
import javax.inject.Inject;
import javax.inject.Named;
@ActivityScope
public class LoggedOutUtils {
@Inject
@Named(AppPrefsConstants.APP_KILLED)
BooleanPreference mAppKilledPreference;
@Inject
@Named(AppPrefsConstants.SAVE_PASSWORD)
BooleanPreference mSavePasswordPreference;
@Inject
NotificationManager mNotificationManager;
@Inject
LoginPresenter mLoginPresenter;
@Inject
Context mContext;
@Inject
LoggedOutUtils() {
}
/**
* Check if the user is still logged in.
*/
public boolean checkLoggedOutPrefs() {
if (!mSavePasswordPreference.get() && mAppKilledPreference.get()) {
mNotificationManager.cancelAll();
mLoginPresenter.logout(Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID), true, null);
return true;
}
return false;
}
}

View File

@@ -1,11 +1,19 @@
package de.beyondsoft.ownchat.utils; package de.beyondsoft.ownchat.utils;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
/** /**
* Created by imarneanu on 2/13/17. * Created by imarneanu on 2/13/17.
*/ */

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 KiB

View File

@@ -4,32 +4,27 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/white" android:background="@android:color/white"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_alignParentBottom="true"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
android:id="@+id/attachFromGalleryBtn" android:id="@+id/attachFromGalleryBtn"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight=".33" android:layout_weight=".50"
android:adjustViewBounds="false" android:adjustViewBounds="false"
android:contentDescription="@null" android:contentDescription="@null"
android:cropToPadding="false" android:cropToPadding="false"
android:layout_margin="10dp"
android:src="@mipmap/ic_file_dialog_gallery" /> android:src="@mipmap/ic_file_dialog_gallery" />
<ImageView <ImageView
android:id="@+id/attachDocumentBtn" android:id="@+id/attachDocumentBtn"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight=".33" android:layout_weight=".50"
android:contentDescription="@null" android:contentDescription="@null"
android:src="@mipmap/ic_file_picker_document" /> android:layout_margin="10dp"
android:src="@mipmap/ic_file_dialog_document" />
<ImageView
android:id="@+id/attachAudioBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:contentDescription="@null"
android:src="@mipmap/ic_file_dialog_audio" />
</LinearLayout> </LinearLayout>

View File

@@ -21,6 +21,15 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:src="@drawable/avatar" /> android:src="@drawable/avatar" />
<ProgressBar
android:id="@+id/profile_avatar_progress_bar"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="70dp"
android:visibility="gone"
tools:visibility="visible" />
<Button <Button
android:id="@+id/profile_change_button" android:id="@+id/profile_change_button"
style="@style/AppTheme.Profile.Button" style="@style/AppTheme.Profile.Button"

View File

@@ -1,44 +1,41 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content">
xmlns:tools="http://schemas.android.com/tools">
<ImageView <ImageView
android:id="@+id/file_iv" android:id="@+id/file_iv"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:src="@drawable/document"
android:layout_margin="10dp" android:layout_margin="10dp"
android:contentDescription="@null" /> android:contentDescription="@null"
android:src="@drawable/document" />
<TextView <TextView
android:id="@+id/file_name_tv" android:id="@+id/file_name_tv"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:text="PPDF_112121_jfioweijf_fiowejfowjfeowf_oifwjefowjifoiwjf_joiwjeofjwiojf0j.pdf" android:layout_marginTop="10dp"
android:textColor="@android:color/black"
android:textSize="18sp"
android:layout_toEndOf="@+id/file_iv" android:layout_toEndOf="@+id/file_iv"
android:layout_toStartOf="@+id/checkbox" android:layout_toStartOf="@+id/checkbox"
android:layout_marginTop="10dp"
android:ellipsize="end" android:ellipsize="end"
/> android:textColor="@android:color/black"
android:textSize="18sp"
tools:text="PPDF_112121_jfioweijf_fiowejfowjfeowf_oifwjefowjifoiwjf_joiwjeofjwiojf0j.pdf" />
<TextView <TextView
android:id="@+id/file_size_tv" android:id="@+id/file_size_tv"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/file_name_tv" android:layout_below="@+id/file_name_tv"
tools:text="1.2MB"
android:layout_toEndOf="@+id/file_iv" android:layout_toEndOf="@+id/file_iv"
android:layout_marginStart="5dp"/> tools:text="1.2MB" />
<CheckBox <CheckBox
android:id="@+id/checkbox" android:id="@+id/checkbox"
android:layout_width="25dp" android:layout_width="25dp"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_margin="20dp" android:layout_margin="20dp" />
/>
</RelativeLayout> </RelativeLayout>

View File

@@ -11,7 +11,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/document" android:background="@android:color/white"
android:contentDescription="@null" android:contentDescription="@null"
android:padding="1dp" android:padding="1dp"
android:scaleType="center" /> android:scaleType="center" />

View File

@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<de.beyondsoft.ownchat.filepicker.views.SquareRelativeLayout <de.beyondsoft.ownchat.filepicker.views.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<ImageView <ImageView
android:id="@+id/iv_photo" android:id="@+id/iv_photo"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/document" android:background="@color/colorWhite"
android:contentDescription="@null" android:contentDescription="@null"
android:padding="1dip" android:padding="1dip"
android:scaleType="center" /> android:scaleType="centerCrop"
tools:src="@drawable/test_image" />
<View <View
android:id="@+id/transparent_bg" android:id="@+id/transparent_bg"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 788 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB