Browse Source

MainActivity intent filters and corresponding Activity start.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
d4bb50be23
  1. 27
      app/src/main/AndroidManifest.xml
  2. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java
  3. 81
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  4. 42
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java
  5. 14
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  6. 10
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  7. 11
      app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java

27
app/src/main/AndroidManifest.xml

@ -26,6 +26,27 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="thmmy.gr"
android:scheme="http"/>
<data
android:host="www.thmmy.gr"
android:scheme="http"/>
<data
android:host="www.thmmy.gr"
android:scheme="https"/>
<data
android:host="thmmy.gr"
android:scheme="https"/>
</intent-filter>
</activity>
<activity
android:name=".activities.LoginActivity"
@ -92,15 +113,15 @@
<service
android:name=".services.DownloadService"
android:exported="false" />
android:exported="false"/>
<receiver
android:name=".receiver.Receiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.media.action.ACTION_DOWNLOAD" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.media.action.ACTION_DOWNLOAD"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
</application>

10
app/src/main/java/gr/thmmy/mthmmy/activities/downloads/DownloadsActivity.java

@ -69,8 +69,6 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
Bundle extras = getIntent().getExtras();
downloadsTitle = extras.getString(BUNDLE_DOWNLOADS_TITLE);
if (downloadsTitle == null || Objects.equals(downloadsTitle, ""))
downloadsTitle = "Downloads";
downloadsUrl = extras.getString(BUNDLE_DOWNLOADS_URL);
if (downloadsUrl != null && !Objects.equals(downloadsUrl, "")) {
ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(downloadsUrl));
@ -83,6 +81,8 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
//Initialize toolbar
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (downloadsTitle == null || Objects.equals(downloadsTitle, ""))
toolbar.setTitle("Downloads");
toolbar.setTitle(downloadsTitle);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
@ -204,7 +204,8 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
@Override
protected void onPostExecute(Void voids) {
if (downloadsTitle == null || Objects.equals(downloadsTitle, ""))
if (downloadsTitle != null && !Objects.equals(downloadsTitle, "") &&
toolbar.getTitle() != downloadsTitle)
toolbar.setTitle(downloadsTitle);
++pagesLoaded;
@ -225,7 +226,8 @@ public class DownloadsActivity extends BaseActivity implements DownloadsAdapter.
Download.DownloadItemType type;
if (ThmmyPage.resolvePageCategory(Uri.parse(thisPageUrl)).is(ThmmyPage.
PageCategory.DOWNLOADS_CATEGORY)) type = Download.DownloadItemType.DOWNLOADS_CATEGORY;
PageCategory.DOWNLOADS_CATEGORY))
type = Download.DownloadItemType.DOWNLOADS_CATEGORY;
else type = Download.DownloadItemType.DOWNLOADS_FILE;
Elements pages = downloadPage.select("a.navPages");

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

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.activities.main;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
@ -8,20 +9,29 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.Toast;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.LoginActivity;
import gr.thmmy.mthmmy.activities.board.BoardActivity;
import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.forum.ForumFragment;
import gr.thmmy.mthmmy.activities.main.recent.RecentFragment;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.topic.TopicActivity;
import gr.thmmy.mthmmy.base.BaseActivity;
import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.model.ThmmyPage;
import gr.thmmy.mthmmy.model.TopicSummary;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE;
import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
@ -35,9 +45,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intentFilter = getIntent();
redirectToActivityFromIntent(intentFilter);
setContentView(R.layout.activity_main);
if (sessionManager.isLoginScreenDefault()) {
if (sessionManager.isLoginScreenDefault())
{
//Go to login
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
@ -46,7 +60,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
}
//Initialize toolbar
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar = (Toolbar)
findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//Initialize drawer
@ -63,6 +80,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
tabLayout.setupWithViewPager(mViewPager);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
redirectToActivityFromIntent(intent);
setIntent(intent);
}
@Override
protected void onResume() {
drawer.setSelection(HOME_ID);
@ -71,11 +95,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
@Override
public void onBackPressed() {
if(drawer.isDrawerOpen()){
if (drawer.isDrawerOpen()) {
drawer.closeDrawer();
return;
}
else if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) {
} else if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) {
super.onBackPressed();
return;
} else {
@ -117,10 +140,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
@Override
public Fragment getItem(int position) {
switch(position) {
case 0: return RecentFragment.newInstance(position +1);
case 1: return ForumFragment.newInstance(position +1);
default: return RecentFragment.newInstance(position +1); //temp (?)
switch (position) {
case 0:
return RecentFragment.newInstance(position + 1);
case 1:
return ForumFragment.newInstance(position + 1);
default:
return RecentFragment.newInstance(position + 1); //temp (?)
}
}
@ -144,4 +170,41 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
}
//-------------------------------FragmentPagerAdapter END-------------------------------------------
private void redirectToActivityFromIntent(Intent intent) {
if (intent != null) {
Uri uri = intent.getData();
if (uri != null) {
Log.d(TAG, uri.toString());
ThmmyPage.PageCategory page = ThmmyPage.resolvePageCategory(uri);
if (!page.is(ThmmyPage.PageCategory.NOT_THMMY)) {
if (page.is(ThmmyPage.PageCategory.BOARD)) {
Intent redirectIntent = new Intent(MainActivity.this, BoardActivity.class);
redirectIntent.putExtra(BUNDLE_BOARD_URL, uri.toString());
redirectIntent.putExtra(BUNDLE_BOARD_TITLE, "");
startActivity(redirectIntent);
} else if (page.is(ThmmyPage.PageCategory.TOPIC)) {
Intent redirectIntent = new Intent(MainActivity.this, TopicActivity.class);
redirectIntent.putExtra(BUNDLE_TOPIC_URL, uri.toString());
redirectIntent.putExtra(BUNDLE_TOPIC_TITLE, "");
startActivity(redirectIntent);
} else if (page.is(ThmmyPage.PageCategory.PROFILE)) {
Intent redirectIntent = new Intent(MainActivity.this, ProfileActivity.class);
redirectIntent.putExtra(BUNDLE_PROFILE_URL, uri.toString());
redirectIntent.putExtra(BUNDLE_PROFILE_THUMBNAIL_URL, "");
redirectIntent.putExtra(BUNDLE_PROFILE_USERNAME, "");
startActivity(redirectIntent);
} else if (page.is(ThmmyPage.PageCategory.DOWNLOADS)) {
Intent redirectIntent = new Intent(MainActivity.this, DownloadsActivity.class);
redirectIntent.putExtra(BUNDLE_DOWNLOADS_URL, uri.toString());
redirectIntent.putExtra(BUNDLE_DOWNLOADS_TITLE, "");
startActivity(redirectIntent);
} else if (!page.is(ThmmyPage.PageCategory.INDEX)) {
Toast.makeText(this, "This thmmy sector is not yet supported.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "This is not thmmy.", Toast.LENGTH_LONG).show();
}
}
}
}
}

42
app/src/main/java/gr/thmmy/mthmmy/activities/profile/ProfileActivity.java

@ -12,6 +12,7 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
@ -50,8 +51,8 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL;
/**
* Activity for user profile. When creating an Intent of this activity you need to bundle a <b>String</b>
* containing this user's profile url using the key {@link #BUNDLE_PROFILE_URL}, a <b>String</b> containing
* this user's avatar url using the key {@link #BUNDLE_THUMBNAIL_URL} and a <b>String</b> containing
* the username using the key {@link #BUNDLE_USERNAME}.
* this user's avatar url using the key {@link #BUNDLE_PROFILE_THUMBNAIL_URL} and a <b>String</b> containing
* the username using the key {@link #BUNDLE_PROFILE_USERNAME}.
*/
public class ProfileActivity extends BaseActivity implements LatestPostsFragment.LatestPostsFragmentInteractionListener {
/**
@ -67,15 +68,16 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
* The key to use when putting user's thumbnail url String to {@link ProfileActivity}'s Bundle.
* If user doesn't have a thumbnail put an empty string or leave it null.
*/
public static final String BUNDLE_THUMBNAIL_URL = "THUMBNAIL_URL";
public static final String BUNDLE_PROFILE_THUMBNAIL_URL = "THUMBNAIL_URL";
/**
* The key to use when putting username String to {@link ProfileActivity}'s Bundle.
* If username is not available put an empty string or leave it null.
*/
public static final String BUNDLE_USERNAME = "USERNAME";
public static final String BUNDLE_PROFILE_USERNAME = "USERNAME";
private static final int THUMBNAIL_SIZE = 200;
private TextView usernameView;
private ImageView thumbnailView;
private TextView personalTextView;
private MaterialProgressBar progressBar;
private FloatingActionButton pmFAB;
@ -84,6 +86,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
private ProfileTask profileTask;
private String personalText;
private String profileUrl;
private String thumbnailUrl;
private String username;
private int tabSelect;
@ -93,9 +96,10 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
setContentView(R.layout.activity_profile);
Bundle extras = getIntent().getExtras();
String thumbnailUrl = extras.getString(BUNDLE_THUMBNAIL_URL);
thumbnailUrl = extras.getString(BUNDLE_PROFILE_THUMBNAIL_URL);
if (thumbnailUrl == null) thumbnailUrl = "";
username = extras.getString(BUNDLE_USERNAME);
Log.d(TAG, "thumbnailUrl = " + thumbnailUrl);
username = extras.getString(BUNDLE_PROFILE_USERNAME);
profileUrl = extras.getString(BUNDLE_PROFILE_URL);
//Initializes graphic elements
@ -111,7 +115,7 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
progressBar = (MaterialProgressBar) findViewById(R.id.progressBar);
ImageView thumbnailView = (ImageView) findViewById(R.id.user_thumbnail);
thumbnailView = (ImageView) findViewById(R.id.user_thumbnail);
if (!Objects.equals(thumbnailUrl, ""))
//noinspection ConstantConditions
Picasso.with(this)
@ -233,8 +237,18 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
if (username == null || Objects.equals(username, "")) {
username = profilePage.
select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr").
first().text();
first().select("td").last().text();
}
Log.d(TAG, "thumbnailUrl = " + thumbnailUrl);
if (thumbnailUrl == null || Objects.equals(thumbnailUrl, "")) { //Maybe there is an avatar
Log.d(TAG, "thumbnailUrl = " + thumbnailUrl);
Element profileAvatar = profilePage
.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) img.avatar")
.first();
if (profileAvatar != null) thumbnailUrl = profileAvatar.attr("abs:src");
}
Log.d(TAG, "thumbnailUrl = " + thumbnailUrl);
;
{ //Finds personal text
Element tmpEl = profilePage.select("td.windowbg:nth-child(2)").first();
@ -268,6 +282,18 @@ public class ProfileActivity extends BaseActivity implements LatestPostsFragment
progressBar.setVisibility(ProgressBar.INVISIBLE);
if (usernameView.getText() != username) usernameView.setText(username);
if (thumbnailUrl != null && !Objects.equals(thumbnailUrl, ""))
//noinspection ConstantConditions
Picasso.with(getApplicationContext())
.load(thumbnailUrl)
.resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
.centerCrop()
.error(ResourcesCompat.getDrawable(getResources()
, R.drawable.ic_default_user_thumbnail, null))
.placeholder(ResourcesCompat.getDrawable(getResources()
, R.drawable.ic_default_user_thumbnail, null))
.transform(new CircleTransform())
.into(thumbnailView);
if (personalText != null) personalTextView.setText(personalText);
setupViewPager(viewPager, profilePage);

14
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -48,8 +48,8 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_USERNAME;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.toQuoteList;
/**
@ -334,10 +334,10 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
Bundle extras = new Bundle();
extras.putString(BUNDLE_PROFILE_URL, currentPost.getProfileURL());
if (currentPost.getThumbnailUrl() == null)
extras.putString(BUNDLE_THUMBNAIL_URL, "");
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, "");
else
extras.putString(BUNDLE_THUMBNAIL_URL, currentPost.getThumbnailUrl());
extras.putString(BUNDLE_USERNAME, currentPost.getAuthor());
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, currentPost.getThumbnailUrl());
extras.putString(BUNDLE_PROFILE_USERNAME, currentPost.getAuthor());
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
@ -572,8 +572,8 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
Intent intent = new Intent(context, ProfileActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_PROFILE_URL, uriString);
extras.putString(BUNDLE_THUMBNAIL_URL, "");
extras.putString(BUNDLE_USERNAME, "");
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, "");
extras.putString(BUNDLE_PROFILE_USERNAME, "");
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

10
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -48,8 +48,8 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_TITLE;
import static gr.thmmy.mthmmy.activities.downloads.DownloadsActivity.BUNDLE_DOWNLOADS_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_USERNAME;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL;
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME;
public abstract class BaseActivity extends AppCompatActivity {
// Client & Cookies
@ -261,10 +261,10 @@ public abstract class BaseActivity extends AppCompatActivity {
Bundle extras = new Bundle();
extras.putString(BUNDLE_PROFILE_URL, "https://www.thmmy.gr/smf/index.php?action=profile");
if (!sessionManager.hasAvatar())
extras.putString(BUNDLE_THUMBNAIL_URL, "");
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, "");
else
extras.putString(BUNDLE_THUMBNAIL_URL, sessionManager.getAvatarLink());
extras.putString(BUNDLE_USERNAME, sessionManager.getUsername());
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, sessionManager.getAvatarLink());
extras.putString(BUNDLE_PROFILE_USERNAME, sessionManager.getUsername());
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

11
app/src/main/java/gr/thmmy/mthmmy/model/ThmmyPage.java

@ -22,6 +22,7 @@ public class ThmmyPage {
* An enum describing a link's target by defining the types:<ul>
* <li>{@link #NOT_THMMY}</li>
* <li>{@link #THMMY}</li>
* <li>{@link #INDEX}</li>
* <li>{@link #UNKNOWN_THMMY}</li>
* <li>{@link #TOPIC}</li>
* <li>{@link #BOARD}</li>
@ -41,6 +42,10 @@ public class ThmmyPage {
* Link points to thmmy.
*/
THMMY,
/**
* Link points to thmmy index page/
*/
INDEX,
/**
* Link points to a thmmy page that's not (yet) supported by the app.
*/
@ -135,6 +140,7 @@ public class ThmmyPage {
final String host = uri.getHost();
final String uriString = uri.toString();
if (Objects.equals(uriString, "thmmy.gr")) return PageCategory.INDEX;
if (Objects.equals(host, "www.thmmy.gr")) {
if (uriString.contains("topic=")) return PageCategory.TOPIC;
else if (uriString.contains("board=")) return PageCategory.BOARD;
@ -150,6 +156,11 @@ public class ThmmyPage {
return PageCategory.DOWNLOADS_FILE;
else if (uriString.contains("action=tpmod;dl"))
return PageCategory.DOWNLOADS_CATEGORY;
else if (uriString.contains("action=forum") || Objects.equals(uriString, "www.thmmy.gr")
|| Objects.equals(uriString, "http://www.thmmy.gr")
|| Objects.equals(uriString, "https://www.thmmy.gr")
|| Objects.equals(uriString, "https://www.thmmy.gr/smf/index.php"))
return PageCategory.INDEX;
Report.v(TAG, "Unknown thmmy link found, link: " + uriString);
return PageCategory.UNKNOWN_THMMY;
}

Loading…
Cancel
Save