Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/src/main/ic_error_red_new-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MattermostPreference {
private static final String LAST_CHANNEL_ID = "last_channel_id";
private static final String TEAM_ID = "team_id";
private static final String SITE_NAME = "site_name";
private static final String MY_E_MAIL = "my_e_mail";

public MattermostPreference(Context context) {
sharedPreferences = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
Expand All @@ -42,6 +43,14 @@ public static synchronized MattermostPreference createInstance(Context context)
return instance;
}

public String getMyEMail() {
return sharedPreferences.getString(MY_E_MAIL, null);
}

public void setMyEMail(String email) {
sharedPreferences.edit().putString(MY_E_MAIL, email).apply();
}

public String getSiteName(){
return sharedPreferences.getString(SITE_NAME,null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.gson.Gson;
import com.kilogramm.mattermost.MattermostApp;
import com.kilogramm.mattermost.MattermostPreference;
import com.kilogramm.mattermost.model.entity.ClientCfg;
import com.kilogramm.mattermost.model.entity.InitObject;
import com.kilogramm.mattermost.model.entity.LicenseCfg;
import com.kilogramm.mattermost.model.entity.Preference.PreferenceRepository;
Expand Down Expand Up @@ -130,7 +129,10 @@ private void initRequest() {
users.add(new User("materMostChannel", "channel", "Notifies everyone in the channel"));

requestLoadChannels();
}, (generalRxActivity1, throwable) -> sendShowError(parceError(throwable, null)));// TODO: 18.01.17 entry point
}, (generalRxActivity1, throwable) -> {
sendShowError(parceError(throwable, null));
relogIfDirectProfileFailed(throwable); // simple logout on error #bugfix
} );// TODO: 18.01.17 entry point

restartableFirst(REQUEST_LOAD_CHANNELS,
() -> ServerMethod.getInstance()
Expand Down Expand Up @@ -355,4 +357,33 @@ private void handleErrorLogin(Throwable e) {
e.printStackTrace();
}
}

/** Give it a throwable (error) from onError() or smth and it gives brings you the login menu
* if the error.getMessage() contains "Unauthorized"
*
* @param throwable a throwable wich should contain "Unauthorized" in its Message
*/
private void relogIfDirectProfileFailed(Throwable throwable) {
if (throwable.getMessage().toLowerCase().contains("unauthorized")) {
try {
Thread.sleep(1500); // waiting to show error msg, seems more clear for users / adjust at will
} catch (Exception e) {
Log.d(TAG + "Sleep", e.getMessage());
}
relog();
}
}

/** Brings you to the MainRxActivity, while clearing the Preferences (old login data)
*
*/
private void relog() {
try {
//MattermostApp.clearPreference();
MattermostPreference.getInstance().setAuthToken(null);
MattermostApp.showMainRxActivity();
} catch (Exception e) {
Log.d(TAG + "Relog", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.Bundle;
import android.view.MenuItem;

import com.kilogramm.mattermost.MattermostPreference;
import com.kilogramm.mattermost.R;
import com.kilogramm.mattermost.databinding.ActivityRxLoginBinding;
import com.kilogramm.mattermost.view.BaseActivity;
Expand All @@ -27,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
binding = DataBindingUtil.setContentView(this, R.layout.activity_rx_login);
binding.setLoginPresenter(getPresenter());
setupToolbar("Sign In", true);
initView();
}

@Override
Expand Down Expand Up @@ -68,4 +70,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void hideKeyboard() {
hideKeyboard(this);
}

/* initialize view for eMail from preferences
*/
private void initView(){
String eMailFromPreferences = MattermostPreference.getInstance().getMyEMail();
if (eMailFromPreferences != null && getPresenter().isValidEmail(eMailFromPreferences)){
binding.editEmail.setText(eMailFromPreferences);
binding.editPassword.requestFocus();
//Editable emailText = binding.editPassword.getText();
//Selection.setSelection(emailText, 0);
getPresenter().mEditEmail = eMailFromPreferences;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private boolean canClickSignIn() {
return mEditEmail.length() != 0 && mEditPassword.length() != 0 && isValidEmail(mEditEmail);
}

private boolean isValidEmail(String email) {
public boolean isValidEmail(String email) { //is now public to use, just checks a string
Pattern p = Patterns.EMAIL_ADDRESS;
Matcher m = p.matcher(email);
return m.matches();
Expand Down Expand Up @@ -198,6 +198,7 @@ private void initRequestLogin() {
.observeOn(AndroidSchedulers.mainThread());
}, (loginRxActivity, user) -> {
MattermostPreference.getInstance().setMyUserId(user.getId());
MattermostPreference.getInstance().setMyEMail(user.getEmail());
realm.executeTransaction(realm1 -> realm1.copyToRealmOrUpdate(user));
requestInitLoad();
}, (loginRxActivity1, throwable) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.util.Log;
import android.view.View;

import com.kilogramm.mattermost.MattermostPreference;
import com.kilogramm.mattermost.R;
import com.kilogramm.mattermost.databinding.ActivityMainBinding;
import com.kilogramm.mattermost.service.MattermostService;
Expand Down Expand Up @@ -43,6 +44,19 @@ private void initView() {
getPresenter().request(getStringUrl());
hideKeyboard();
});

// get url from preferences
String urlFromPreferences = MattermostPreference.getInstance().getBaseUrl();
if (urlFromPreferences != null){
if (!urlFromPreferences.startsWith("https://") || !urlFromPreferences.startsWith("http://")){
urlFromPreferences = "https://" + urlFromPreferences;
}
binding.urlEditText.setText(urlFromPreferences);
if (checkEnteredUrl(getStringUrl()) || (binding.urlEditText.getText().length() == 0)){
setShowNextButton(true);
}
}

binding.urlEditText.addTextChangedListener(textWatcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
headers.put("Authorization", "Bearer " + MattermostPreference.getInstance().getAuthToken());
DisplayImageOptions options = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.EXACTLY)
.showImageOnFail(R.drawable.ic_error_red_24dp)
.showImageOnFail(R.drawable.ic_error_red_new)
.resetViewBeforeLoading(true)
.cacheInMemory(true)
.cacheOnDisk(true)
.extraForDownloader(headers)
.considerExifParams(true)
.build();

String preview_url = "https://mattermost.kilograpp.com/api/v3/files/"
String preview_url = "https://"
+ MattermostPreference.getInstance().getBaseUrl()
+ "/api/v3/files/"
+ mFileInfo.getId()
+ "/get_preview";

Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_error_red_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_error_red_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_error_red_new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.