Browse Source

Added shared preferences, main activity -> launcher & main, login activity called when needed, logout tweaks

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
82c0605b95
  1. 9
      app/build.gradle
  2. 7
      app/src/main/AndroidManifest.xml
  3. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java
  4. 43
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  5. 80
      app/src/main/java/gr/thmmy/mthmmy/activities/MainActivity.java
  6. 91
      app/src/main/java/gr/thmmy/mthmmy/utils/Thmmy.java
  7. 8
      app/src/main/res/drawable/page_first.xml
  8. 8
      app/src/main/res/drawable/page_last.xml
  9. 8
      app/src/main/res/drawable/page_next.xml
  10. 8
      app/src/main/res/drawable/page_previous.xml

9
app/build.gradle

@ -21,9 +21,10 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1' compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.1' compile 'com.android.support:design:25.0.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1' compile 'com.squareup.okhttp3:okhttp:3.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.jsoup:jsoup:1.10.1' compile 'org.jsoup:jsoup:1.10.1'
compile 'com.android.support:support-v4:25.0.1' compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1' compile 'com.android.support:cardview-v7:25.0.1'
@ -33,6 +34,4 @@ dependencies {
compile('com.mikepenz:materialdrawer:5.7.0@aar') { compile('com.mikepenz:materialdrawer:5.7.0@aar') {
transitive = true transitive = true
} }
} }

7
app/src/main/AndroidManifest.xml

@ -12,9 +12,11 @@
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name=".activities.LoginActivity" android:name=".activities.MainActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<intent-filter> <intent-filter>
@ -23,9 +25,8 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.LoginActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
</activity> </activity>

7
app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -19,6 +20,12 @@ public class BaseActivity extends AppCompatActivity {
protected static Thmmy.LoginData loginData; protected static Thmmy.LoginData loginData;
private static boolean init =false; //To initialize stuff only once per app start private static boolean init =false; //To initialize stuff only once per app start
//Shared preferences
public static final String SHARED_PREFS_NAME = "thmmySharedPrefs";
public static final String USER_NAME = "userNameKey";
public static final String GUEST_PREF_USERNAME = "GUEST";
public static final String IS_LOGGED_IN = "isLogedIn";
public static CookieJar getCookieJar() public static CookieJar getCookieJar()
{ {
return cookieJar; return cookieJar;

43
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.activities;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -22,20 +23,15 @@ import static gr.thmmy.mthmmy.utils.Thmmy.login;
public class LoginActivity extends BaseActivity { public class LoginActivity extends BaseActivity {
private static final String TAG = "LoginActivity"; private static final String TAG = "LoginActivity";
private static boolean passed=false; //becomes true after (guest) login - to redirect to Main
Button btnLogin; Button btnLogin;
Button btnGuest; Button btnGuest;
private EditText inputUsername; private EditText inputUsername;
private EditText inputPassword; private EditText inputPassword;
private String username;
private String password;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
/*if(passed) //redirect to MainActivity if user passed this one at least once
{
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}*/
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
@ -50,27 +46,31 @@ public class LoginActivity extends BaseActivity {
public void onClick(View view) { public void onClick(View view) {
Log.d(TAG, "Login"); Log.d(TAG, "Login");
username = inputUsername.getText().toString().trim();
password = inputPassword.getText().toString().trim();
// Check for empty data in the form // Check for empty data in the form
if (!validate()) { if (!validate()) {
onLoginFailed(); onLoginFailed();
return; return;
} }
String username = inputUsername.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
// login user // login user
new LoginTask().execute(username,password); new LoginTask().execute(username, password);
} }
}); });
// Link to Register Screen // Guest Button Action
btnGuest.setOnClickListener(new View.OnClickListener() { btnGuest.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) { public void onClick(View view) {
SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString(USER_NAME, GUEST_PREF_USERNAME);
editor.putBoolean(IS_LOGGED_IN, true);
editor.apply();
Intent intent = new Intent(LoginActivity.this, MainActivity.class); Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent); startActivity(intent);
passed=true;
finish(); finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
} }
@ -92,10 +92,7 @@ public class LoginActivity extends BaseActivity {
public boolean validate() { public boolean validate() {
boolean valid = true; boolean valid = true;
String email = inputUsername.getText().toString(); if (username.isEmpty()) {
String password = inputPassword.getText().toString();
if (email.isEmpty()) {
inputUsername.setError("Enter a valid username"); inputUsername.setError("Enter a valid username");
valid = false; valid = false;
} else { } else {
@ -112,13 +109,12 @@ public class LoginActivity extends BaseActivity {
return valid; return valid;
} }
private class LoginTask extends AsyncTask<String, Void, Integer> private class LoginTask extends AsyncTask<String, Void, Integer> {
{
ProgressDialog progressDialog; ProgressDialog progressDialog;
@Override @Override
protected Integer doInBackground(String... params) { protected Integer doInBackground(String... params) {
setLoginData(login(params[0], params[1],"-1")); setLoginData(login(params[0], params[1], "-1"));
return loginData.getStatus(); return loginData.getStatus();
} }
@ -162,13 +158,16 @@ public class LoginActivity extends BaseActivity {
.show(); .show();
break; break;
case LOGGED_IN: case LOGGED_IN:
//progressDialog.dismiss(); SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString(USER_NAME, username);
editor.putBoolean(IS_LOGGED_IN, true);
editor.apply();
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
"Login successful!", Toast.LENGTH_LONG) "Login successful!", Toast.LENGTH_LONG)
.show(); .show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class); Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent); startActivity(intent);
passed=true;
finish(); finish();
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out); overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
break; break;

80
app/src/main/java/gr/thmmy/mthmmy/activities/MainActivity.java

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.activities; package gr.thmmy.mthmmy.activities;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
@ -11,18 +12,17 @@ import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast;
import org.jsoup.nodes.Document;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.data.TopicSummary; import gr.thmmy.mthmmy.data.TopicSummary;
import gr.thmmy.mthmmy.sections.recent.RecentFragment; import gr.thmmy.mthmmy.sections.recent.RecentFragment;
import gr.thmmy.mthmmy.utils.Thmmy; import gr.thmmy.mthmmy.utils.Thmmy;
public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener {
{ /**
private SectionsPagerAdapter mSectionsPagerAdapter; * The {@link ViewPager} that will host the section contents.
private ViewPager mViewPager; /** The {@link ViewPager} that will host the section contents.*/ */
private Menu menu; private Menu menu;
@ -31,14 +31,22 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
if (!prefs.getBoolean(IS_LOGGED_IN, false)) {
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each section of the activity // Create the adapter that will return a fragment for each section of the activity
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container); ViewPager mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
@ -55,10 +63,11 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
this.menu=menu; this.menu = menu;
getMenuInflater().inflate(R.menu.menu_main, menu); getMenuInflater().inflate(R.menu.menu_main, menu);
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
if(loginData.getStatus()== Thmmy.LOGGED_IN) if (prefs.getBoolean(IS_LOGGED_IN, false)
&& prefs.getString(USER_NAME, null) != GUEST_PREF_USERNAME)
hideLogin(); hideLogin();
else else
hideLogout(); hideLogout();
@ -67,20 +76,17 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) public boolean onOptionsItemSelected(MenuItem item) {
{
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.action_about) if (id == R.id.action_about) {
{
Intent i = new Intent(MainActivity.this, AboutActivity.class); Intent i = new Intent(MainActivity.this, AboutActivity.class);
startActivity(i); startActivity(i);
return true; return true;
} } else if (id == R.id.action_logout)
else if (id == R.id.action_logout)
new LogoutTask().execute(); new LogoutTask().execute();
else{ else {
Intent intent = new Intent(MainActivity.this,LoginActivity.class); Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent); startActivity(intent);
finish(); finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
@ -89,26 +95,22 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void hideLogin() private void hideLogin() {
{
MenuItem login = menu.findItem(R.id.action_login); MenuItem login = menu.findItem(R.id.action_login);
MenuItem logout = menu.findItem(R.id.action_logout); MenuItem logout = menu.findItem(R.id.action_logout);
login.setVisible(false); login.setVisible(false);
logout.setVisible(true); logout.setVisible(true);
} }
private void hideLogout() private void hideLogout() {
{
MenuItem login = menu.findItem(R.id.action_login); MenuItem login = menu.findItem(R.id.action_login);
MenuItem logout = menu.findItem(R.id.action_logout); MenuItem logout = menu.findItem(R.id.action_logout);
login.setVisible(true); login.setVisible(true);
logout.setVisible(false); logout.setVisible(false);
} }
@Override @Override
public void onFragmentInteraction(TopicSummary topicSummary) public void onFragmentInteraction(TopicSummary topicSummary) {
{
Intent i = new Intent(MainActivity.this, TopicActivity.class); Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra("TOPIC_URL", topicSummary.getTopicUrl()); i.putExtra("TOPIC_URL", topicSummary.getTopicUrl());
i.putExtra("TOPIC_TITLE", topicSummary.getTitle()); i.putExtra("TOPIC_TITLE", topicSummary.getTitle());
@ -116,6 +118,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
} }
//---------------------------------FragmentPagerAdapter--------------------------------------------- //---------------------------------FragmentPagerAdapter---------------------------------------------
/** /**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages. If it becomes too memory intensive, * one of the sections/tabs/pages. If it becomes too memory intensive,
@ -154,29 +157,26 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
} }
} }
private class LogoutTask extends AsyncTask<Void, Void, Integer> {
private class LogoutTask extends AsyncTask<Void, Void, Integer> protected Integer doInBackground(Void... voids) {
{
protected Integer doInBackground(Void... voids)
{
return Thmmy.logout(loginData); return Thmmy.logout(loginData);
} }
protected void onPreExecute() { protected void onPreExecute() {
//TODO: a progressbar maybe? //TODO: a progressbar maybe?
} }
protected void onPostExecute(Integer result) protected void onPostExecute(Integer result) {
{ if (result == Thmmy.LOGGED_OUT) {
if(result==Thmmy.LOGGED_OUT) SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString(USER_NAME, null);
editor.putBoolean(IS_LOGGED_IN, false);
editor.apply();
Toast.makeText(getBaseContext(), "Logged out successfully!", Toast.LENGTH_LONG).show();
hideLogout(); hideLogout();
else } else
hideLogin(); hideLogin();
} }
} }
} }

91
app/src/main/java/gr/thmmy/mthmmy/utils/Thmmy.java

@ -27,32 +27,27 @@ import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
public class Thmmy public class Thmmy {
{
private static final HttpUrl loginUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=login2"); private static final HttpUrl loginUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php?action=login2");
private static final HttpUrl indexUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php"); private static final HttpUrl indexUrl = HttpUrl.parse("https://www.thmmy.gr/smf/index.php");
public static final int LOGGED_OUT = 0; public static final int LOGGED_OUT = 0;
public static final int LOGGED_IN = 1; public static final int LOGGED_IN = 1;
public static final int WRONG_USER= 2; public static final int WRONG_USER = 2;
public static final int WRONG_PASSWORD= 3; public static final int WRONG_PASSWORD = 3;
public static final int FAILED= 4; public static final int FAILED = 4;
public static final int CERTIFICATE_ERROR = 5; public static final int CERTIFICATE_ERROR = 5;
public static final int OTHER_ERROR = 6; public static final int OTHER_ERROR = 6;
//-------------------------------------------LOGIN-------------------------------------------------- //-------------------------------------------LOGIN--------------------------------------------------
//Two options: (username, password, duration) or nothing - cookies //Two options: (username, password, duration) or nothing - cookies
public static LoginData login(String... strings) public static LoginData login(String... strings) {
{ Log.d("Login", "Logging in...");
Log.d("Login","Logging in...");
LoginData loginData = new LoginData(); LoginData loginData = new LoginData();
Request request; Request request;
if(strings.length==3) if (strings.length == 3) {
{
String loginName = strings[0]; String loginName = strings[0];
String password = strings[1]; String password = strings[1];
String duration = strings[2]; String duration = strings[2];
@ -68,9 +63,7 @@ public class Thmmy
.url(loginUrl) .url(loginUrl)
.post(formBody) .post(formBody)
.build(); .build();
} } else {
else
{
request = new Request.Builder() request = new Request.Builder()
.url(loginUrl) .url(loginUrl)
.build(); .build();
@ -78,39 +71,33 @@ public class Thmmy
OkHttpClient client = BaseActivity.getClient(); OkHttpClient client = BaseActivity.getClient();
try try {
{
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
Document document = Jsoup.parse(response.body().string()); Document document = Jsoup.parse(response.body().string());
Element logout = document.getElementById("logoutbtn"); Element logout = document.getElementById("logoutbtn");
if (logout != null) if (logout != null) {
{
Log.i("Login", "Login successful"); Log.i("Login", "Login successful");
setPersistentCookieSession(); setPersistentCookieSession();
loginData.setUsername(extractUserName(document)); loginData.setUsername(extractUserName(document));
loginData.setLogoutLink(HttpUrl.parse(logout.attr("href"))); loginData.setLogoutLink(HttpUrl.parse(logout.attr("href")));
loginData.setStatus(LOGGED_IN); loginData.setStatus(LOGGED_IN);
} } else {
else
{
Log.w("Login", "Login failed"); Log.w("Login", "Login failed");
loginData.setStatus(FAILED); loginData.setStatus(FAILED);
//Making error more specific //Making error more specific
Elements error = document.select("b:contains(That username does not exist.)"); Elements error = document.select("b:contains(That username does not exist.)");
if (error.size()==1) if (error.size() == 1) {
{
loginData.setStatus(WRONG_USER); loginData.setStatus(WRONG_USER);
Log.d("Login","Wrong Username"); Log.d("Login", "Wrong Username");
} }
error = document.select("body:contains(Password incorrect)"); error = document.select("body:contains(Password incorrect)");
if (error.size()==1) if (error.size() == 1) {
{ Log.d("Login", "Wrong Password");
Log.d("Login","Wrong Password");
loginData.setStatus(WRONG_PASSWORD); loginData.setStatus(WRONG_PASSWORD);
} }
@ -126,21 +113,17 @@ public class Thmmy
loginData.setStatus(OTHER_ERROR); loginData.setStatus(OTHER_ERROR);
} }
return loginData; return loginData;
} }
//To maintain data between activities/ between activity state change (possibly temporary solution) //To maintain data between activities/ between activity state change (possibly temporary solution)
public static class LoginData implements Parcelable public static class LoginData implements Parcelable {
{
private int status; private int status;
private String username; private String username;
private HttpUrl logoutLink; private HttpUrl logoutLink;
public LoginData() {} public LoginData() {
}
public String getUsername() { public String getUsername() {
return username; return username;
@ -192,18 +175,16 @@ public class Thmmy
private LoginData(Parcel in) { private LoginData(Parcel in) {
status = in.readInt(); status = in.readInt();
username=in.readString(); username = in.readString();
logoutLink=HttpUrl.parse(in.readString()); logoutLink = HttpUrl.parse(in.readString());
} }
} }
private static boolean setPersistentCookieSession() private static boolean setPersistentCookieSession() {
{
List<Cookie> cookieList = BaseActivity.getCookieJar().loadForRequest(HttpUrl.parse("https://www.thmmy.gr")); List<Cookie> cookieList = BaseActivity.getCookieJar().loadForRequest(HttpUrl.parse("https://www.thmmy.gr"));
if (cookieList.size() == 2) { if (cookieList.size() == 2) {
if ((cookieList.get(0).name().equals("THMMYgrC00ki3")) && (cookieList.get(1).name().equals("PHPSESSID"))) if ((cookieList.get(0).name().equals("THMMYgrC00ki3")) && (cookieList.get(1).name().equals("PHPSESSID"))) {
{
Cookie.Builder builder = new Cookie.Builder(); Cookie.Builder builder = new Cookie.Builder();
builder.name(cookieList.get(1).name()) builder.name(cookieList.get(1).name())
.value(cookieList.get(1).value()) .value(cookieList.get(1).value())
@ -221,10 +202,8 @@ public class Thmmy
//-------------------------------------LOGIN ENDS----------------------------------------------- //-------------------------------------LOGIN ENDS-----------------------------------------------
//--------------------------------------LOGOUT-------------------------------------------------- //--------------------------------------LOGOUT--------------------------------------------------
public static int logout(LoginData loginData) public static int logout(LoginData loginData) {
{
OkHttpClient client = BaseActivity.getClient(); OkHttpClient client = BaseActivity.getClient();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(loginData.getLogoutLink()) .url(loginData.getLogoutLink())
@ -234,16 +213,13 @@ public class Thmmy
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
Document document = Jsoup.parse(response.body().string()); Document document = Jsoup.parse(response.body().string());
Elements login = document.select("[value=Login]"); Elements login = document.select("[value=Login]");
((PersistentCookieJar) BaseActivity.getCookieJar()).clear(); ((PersistentCookieJar) BaseActivity.getCookieJar()).clear();
if(!login.isEmpty()) if (!login.isEmpty()) {
{
Log.i("Logout", "Logout successful"); Log.i("Logout", "Logout successful");
loginData.setStatus(LOGGED_OUT); loginData.setStatus(LOGGED_OUT);
return LOGGED_OUT; return LOGGED_OUT;
} } else {
else
{
Log.w("Logout", "Logout failed"); Log.w("Logout", "Logout failed");
return FAILED; return FAILED;
} }
@ -260,22 +236,15 @@ public class Thmmy
} }
//----------------------------------------LOGOUT ENDS----------------------------------------------- //----------------------------------------LOGOUT ENDS-----------------------------------------------
//-------------------------------------------MISC---------------------------------------------------
public static String extractUserName(Document doc) {
//-------------------------------------------MISC--------------------------------------------------- if (doc != null) {
public static String extractUserName(Document doc)
{
if(doc!=null)
{
Elements user = doc.select("div[id=myuser] > h3"); Elements user = doc.select("div[id=myuser] > h3");
if (user.size()==1) if (user.size() == 1) {
{
String txt = user.first().ownText(); String txt = user.first().ownText();
Pattern pattern = Pattern.compile(", (.*?),"); Pattern pattern = Pattern.compile(", (.*?),");

8
app/src/main/res/drawable/page_first.xml

@ -1,8 +0,0 @@
<!-- drawable/page_first.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path android:fillColor="#000" android:pathData="M18.41,16.59L13.82,12L18.41,7.41L17,6L11,12L17,18L18.41,16.59M6,6H8V18H6V6Z" />
</vector>

8
app/src/main/res/drawable/page_last.xml

@ -1,8 +0,0 @@
<!-- drawable/page_last.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path android:fillColor="#000" android:pathData="M5.59,7.41L10.18,12L5.59,16.59L7,18L13,12L7,6L5.59,7.41M16,6H18V18H16V6Z" />
</vector>

8
app/src/main/res/drawable/page_next.xml

@ -1,8 +0,0 @@
<!-- drawable/page_next.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path android:fillColor="#000" android:pathData="M16,18H18V6H16M6,18L14.5,12L6,6V18Z" />
</vector>

8
app/src/main/res/drawable/page_previous.xml

@ -1,8 +0,0 @@
<!-- drawable/page_previous.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path android:fillColor="#000" android:pathData="M6,18V6H8V18H6M9.5,12L18,6V18L9.5,12Z" />
</vector>
Loading…
Cancel
Save