Browse Source

move shoutbox to drawer

pull/61/merge
Thodoris1999 6 years ago
parent
commit
019728c12a
  1. 3
      app/build.gradle
  2. 8
      app/src/main/AndroidManifest.xml
  3. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/SendShoutTask.java
  5. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java
  6. 39
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java
  7. 174
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java
  8. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java
  9. 152
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  10. 58
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java
  11. 16
      app/src/main/res/drawable/refresh_label_background.xml
  12. 32
      app/src/main/res/layout/activity_shoutbox.xml
  13. 32
      app/src/main/res/layout/fragment_shoutbox.xml

3
app/build.gradle

@ -40,7 +40,7 @@ tasks.whenTaskAdded { task ->
task.getDependsOn().add({
def inputFile = new File("app/google-services.json")
def json = new JsonSlurper().parseText(inputFile.text)
if(json.project_info.project_id != "mthmmy-release-3aef0")
if (json.project_info.project_id != "mthmmy-release-3aef0")
throw new GradleException('Please supply the correct google-services.json for release or manually change the id above!')
})
}
@ -77,6 +77,7 @@ dependencies {
implementation 'net.gotev:uploadservice-okhttp:3.4.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
}
apply plugin: 'com.google.gms.google-services'

8
app/src/main/AndroidManifest.xml

@ -154,6 +154,14 @@
android:configChanges="orientation|screenSize"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.shoutbox.ShoutboxActivity"
android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.main.MainActivity" />
</activity>
</application>
</manifest>

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

@ -23,7 +23,6 @@ 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.main.shoutbox.ShoutboxFragment;
import gr.thmmy.mthmmy.activities.main.unread.UnreadFragment;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
@ -79,10 +78,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT");
sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM");
if (sessionManager.isLoggedIn()) {
if (sessionManager.isLoggedIn())
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD");
sectionsPagerAdapter.addFragment(ShoutboxFragment.newInstance(4), "SHOUTBOX");
}
//Set up the ViewPager with the sections adapter.
viewPager = findViewById(R.id.container);
@ -102,8 +99,6 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp));
}else if (i == 2) {
tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp));
} else if (i == 3) {
tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_announcement));
}
}
@ -224,15 +219,12 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
}
public void updateTabs() {
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 4) {
sectionsPagerAdapter.removeFragment(3);
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) {
sectionsPagerAdapter.removeFragment(2);
}
else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) {
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD");
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(4), "SHOUTBOX");
tabLayout.getTabAt(3).setIcon(R.drawable.ic_fiber_new_white_24dp);
tabLayout.getTabAt(4).setIcon(R.drawable.ic_announcement);
}
}
//-------------------------------FragmentPagerAdapter END-------------------------------------------

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/SendShoutTask.java → app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/SendShoutTask.java

@ -1,4 +1,4 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
package gr.thmmy.mthmmy.activities.shoutbox;
import org.jsoup.nodes.Document;

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutAdapter.java → app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutAdapter.java

@ -1,4 +1,4 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
package gr.thmmy.mthmmy.activities.shoutbox;
import android.annotation.TargetApi;
import android.content.Context;

39
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java

@ -0,0 +1,39 @@
package gr.thmmy.mthmmy.activities.shoutbox;
import android.os.Bundle;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseActivity;
public class ShoutboxActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shoutbox);
//Initialize toolbar
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Shoutbox");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
createDrawer();
drawer.setSelection(SHOUTBOX_ID);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, ShoutboxFragment.newInstance())
.commitNow();
}
}
@Override
protected void onResume() {
drawer.setSelection(SHOUTBOX_ID);
super.onResume();
}
}

174
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java → app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java

@ -1,6 +1,5 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
package gr.thmmy.mthmmy.activities.shoutbox;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -8,16 +7,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.editorview.EditorView;
import gr.thmmy.mthmmy.editorview.EmojiKeyboard;
import gr.thmmy.mthmmy.model.Shout;
@ -25,85 +22,30 @@ import gr.thmmy.mthmmy.model.Shoutbox;
import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.NetworkResultCodes;
import gr.thmmy.mthmmy.viewmodel.ShoutboxViewModel;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber;
public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.EmojiKeyboardOwner {
private static final String TAG = "ShoutboxFragment";
public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKeyboardOwner {
private MaterialProgressBar progressBar;
private TextView refreshLabel;
private ShoutboxTask shoutboxTask;
private ShoutAdapter shoutAdapter;
private EmojiKeyboard emojiKeyboard;
private EditorView editorView;
private Shoutbox shoutbox;
private ValueAnimator animator;
public static ShoutboxFragment newInstance(int sectionNumber) {
ShoutboxFragment fragment = new ShoutboxFragment();
Bundle args = new Bundle();
args.putString(ARG_TAG, TAG);
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
private void onShoutboxTaskSarted() {
Timber.i("Starting shoutbox task...");
hideRefreshLabel();
progressBar.setVisibility(View.VISIBLE);
}
private void onSendShoutTaskStarted() {
Timber.i("Start sending a shout...");
progressBar.setVisibility(View.VISIBLE);
}
private void onSendShoutTaskFinished(int resultCode, Void ignored) {
editorView.setAlpha(1f);
editorView.setEnabled(true);
progressBar.setVisibility(View.INVISIBLE);
showRefreshLabel();
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shout was sent successfully");
editorView.getEditText().getText().clear();
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to send shout");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
}
}
private ShoutboxViewModel mViewModel;
private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) {
progressBar.setVisibility(View.INVISIBLE);
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shoutbox loaded successfully");
shoutAdapter.setShouts(shoutbox.getShouts());
shoutAdapter.notifyDataSetChanged();
this.shoutbox = shoutbox;
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to retreive shoutbox due to network error");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
} else {
Timber.wtf("Failed to retreive shoutbox due to unknown error");
Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show();
}
public static ShoutboxFragment newInstance() {
return new ShoutboxFragment();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_shoutbox, container, false);
refreshLabel = rootView.findViewById(R.id.refresh_label);
refreshLabel.setOnClickListener(v -> {
shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
});
progressBar = rootView.findViewById(R.id.progressBar);
CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview);
shoutAdapter = new ShoutAdapter(getContext(), new Shout[0]);
@ -117,19 +59,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0);
return false;
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
showRefreshLabel();
} else {
hideRefreshLabel();
}
}
});
shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard);
editorView = rootView.findViewById(R.id.edior_view);
@ -137,17 +66,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
InputConnection ic = editorView.getInputConnection();
setEmojiKeyboardInputConnection(ic);
editorView.setOnSubmitListener(view -> {
if (shoutbox == null) return;
if (mViewModel.getShoutboxMutableLiveData().getValue() == null) return;
if (editorView.getText().toString().isEmpty()) {
editorView.setError("Required");
return;
}
editorView.setAlpha(0.5f);
editorView.setEnabled(false);
setEmojiKeyboardVisible(false);
new SendShoutTask(this::onSendShoutTaskStarted, this::onSendShoutTaskFinished)
.execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(),
shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl());
mViewModel.sendShout(editorView.getText().toString());
});
editorView.hideMarkdown();
editorView.setOnTouchListener((view, motionEvent) -> {
@ -160,30 +84,64 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
return rootView;
}
private void hideRefreshLabel() {
if (refreshLabel.getVisibility() == View.GONE) return;
if (animator != null) animator.cancel();
animator = getRefreshLabelAnimation();
animator.start();
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this).get(ShoutboxViewModel.class);
mViewModel.getShoutboxMutableLiveData().observe(this, shoutbox -> {
if (shoutbox != null) {
Timber.i("Shoutbox loaded successfully");
shoutAdapter.setShouts(shoutbox.getShouts());
shoutAdapter.notifyDataSetChanged();
}
});
mViewModel.setOnShoutboxTaskStarted(this::onShoutboxTaskSarted);
mViewModel.setOnShoutboxTaskFinished(this::onShoutboxTaskFinished);
mViewModel.setOnSendShoutTaskStarted(this::onSendShoutTaskStarted);
mViewModel.setOnSendShoutTaskFinished(this::onSendShoutTaskFinished);
mViewModel.loadShoutbox();
}
private void showRefreshLabel() {
if (refreshLabel.getVisibility() == View.VISIBLE) return;
if (animator != null) animator.cancel();
animator = getRefreshLabelAnimation();
animator.reverse();
private void onShoutboxTaskSarted() {
Timber.i("Starting shoutbox task...");
progressBar.setVisibility(View.VISIBLE);
}
private ValueAnimator getRefreshLabelAnimation() {
ValueAnimator animator = ValueAnimator.ofFloat(-200, 0);
animator.addUpdateListener(valueAnimator -> {
if (((Float) valueAnimator.getAnimatedValue()).intValue() == 1) refreshLabel.setVisibility(View.VISIBLE);
if (((Float) valueAnimator.getAnimatedValue()).intValue() == -199) refreshLabel.setVisibility(View.GONE);
refreshLabel.setTranslationY((float) valueAnimator.getAnimatedValue());
});
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(200);
return animator;
private void onSendShoutTaskStarted() {
Timber.i("Start sending a shout...");
editorView.setAlpha(0.5f);
editorView.setEnabled(false);
setEmojiKeyboardVisible(false);
progressBar.setVisibility(View.VISIBLE);
}
private void onSendShoutTaskFinished(int resultCode, Void ignored) {
editorView.setAlpha(1f);
editorView.setEnabled(true);
progressBar.setVisibility(View.INVISIBLE);
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shout was sent successfully");
editorView.getEditText().getText().clear();
shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to send shout");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
}
}
private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) {
progressBar.setVisibility(View.INVISIBLE);
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
mViewModel.setShoutbox(shoutbox);
} else if (resultCode == NetworkResultCodes.NETWORK_ERROR) {
Timber.w("Failed to retreive shoutbox due to network error");
Toast.makeText(getContext(), "NetworkError", Toast.LENGTH_SHORT).show();
} else {
Timber.wtf("Failed to retreive shoutbox due to unknown error");
Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show();
}
}
@Override

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java → app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxTask.java

@ -1,4 +1,4 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
package gr.thmmy.mthmmy.activities.shoutbox;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

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

@ -49,6 +49,7 @@ import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.MainActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
import gr.thmmy.mthmmy.activities.shoutbox.ShoutboxActivity;
import gr.thmmy.mthmmy.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.ThmmyFile;
@ -145,6 +146,7 @@ public abstract class BaseActivity extends AppCompatActivity {
protected static final int LOG_ID = 4;
protected static final int ABOUT_ID = 5;
protected static final int SETTINGS_ID = 6;
protected static final int SHOUTBOX_ID = 7;
private AccountHeader accountHeader;
private ProfileDrawerItem profileDrawerItem;
@ -159,7 +161,7 @@ public abstract class BaseActivity extends AppCompatActivity {
final int selectedPrimaryColor = ContextCompat.getColor(this, R.color.primary_dark);
final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent);
PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem;
PrimaryDrawerItem homeItem, bookmarksItem, settingsItem, aboutItem, shoutboxItem;
IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, uploadIcon, uploadIconSelected, settingsIcon,
settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected;
@ -230,6 +232,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.withIcon(homeIcon)
.withSelectedIcon(homeIconSelected);
shoutboxItem = new PrimaryDrawerItem()
.withTextColor(primaryColor)
.withSelectedColor(selectedPrimaryColor)
.withSelectedTextColor(selectedSecondaryColor)
.withIdentifier(SHOUTBOX_ID)
.withName(R.string.shoutbox)
.withIcon(R.drawable.ic_announcement)
.withIconColor(primaryColor)
.withSelectedIconColor(selectedSecondaryColor);
if (sessionManager.isLoggedIn()) //When logged in
{
@ -301,26 +312,23 @@ public abstract class BaseActivity extends AppCompatActivity {
.withSelectionListEnabledForSingleProfile(false)
.withHeaderBackground(R.color.primary)
.addProfiles(profileDrawerItem)
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
if (sessionManager.isLoggedIn()) {
Intent intent = new Intent(BaseActivity.this, ProfileActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_PROFILE_URL, "https://www.thmmy.gr/smf/index.php?action=profile");
if (!sessionManager.hasAvatar())
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, "");
else
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);
return false;
}
return true;
.withOnAccountHeaderListener((view, profile, currentProfile) -> {
if (sessionManager.isLoggedIn()) {
Intent intent = new Intent(BaseActivity.this, ProfileActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_PROFILE_URL, "https://www.thmmy.gr/smf/index.php?action=profile");
if (!sessionManager.hasAvatar())
extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, "");
else
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);
return false;
}
return true;
})
.build();
@ -331,63 +339,65 @@ public abstract class BaseActivity extends AppCompatActivity {
.withDrawerWidthDp((int) BaseApplication.getInstance().getDpWidth() / 2)
.withSliderBackgroundColor(ContextCompat.getColor(this, R.color.primary_light))
.withAccountHeader(accountHeader)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem.equals(HOME_ID)) {
if (!(BaseActivity.this instanceof MainActivity)) {
Intent intent = new Intent(BaseActivity.this, MainActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(DOWNLOADS_ID)) {
if (!(BaseActivity.this instanceof DownloadsActivity)) {
Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_DOWNLOADS_URL, "");
extras.putString(BUNDLE_DOWNLOADS_TITLE, null);
intent.putExtras(extras);
startActivity(intent);
}
} else if (drawerItem.equals(UPLOAD_ID)) {
if (!(BaseActivity.this instanceof UploadActivity)) {
Intent intent = new Intent(BaseActivity.this, UploadActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(BOOKMARKS_ID)) {
if (!(BaseActivity.this instanceof BookmarkActivity)) {
Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(LOG_ID)) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{
Intent intent = new Intent(BaseActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
} else
new LogoutTask().execute();
} else if (drawerItem.equals(ABOUT_ID)) {
if (!(BaseActivity.this instanceof AboutActivity)) {
Intent intent = new Intent(BaseActivity.this, AboutActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(SETTINGS_ID)) {
if (!(BaseActivity.this instanceof SettingsActivity)) {
Intent intent = new Intent(BaseActivity.this, SettingsActivity.class);
startActivity(intent);
}
.withOnDrawerItemClickListener((view, position, drawerItem) -> {
if (drawerItem.equals(HOME_ID)) {
if (!(BaseActivity.this instanceof MainActivity)) {
Intent intent = new Intent(BaseActivity.this, MainActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(SHOUTBOX_ID)) {
if (!(BaseActivity.this instanceof ShoutboxActivity)) {
Intent intent = new Intent(BaseActivity.this, ShoutboxActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(DOWNLOADS_ID)) {
if (!(BaseActivity.this instanceof DownloadsActivity)) {
Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_DOWNLOADS_URL, "");
extras.putString(BUNDLE_DOWNLOADS_TITLE, null);
intent.putExtras(extras);
startActivity(intent);
}
} else if (drawerItem.equals(UPLOAD_ID)) {
if (!(BaseActivity.this instanceof UploadActivity)) {
Intent intent = new Intent(BaseActivity.this, UploadActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(BOOKMARKS_ID)) {
if (!(BaseActivity.this instanceof BookmarkActivity)) {
Intent intent = new Intent(BaseActivity.this, BookmarkActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(LOG_ID)) {
if (!sessionManager.isLoggedIn()) //When logged out or if user is guest
{
Intent intent = new Intent(BaseActivity.this, LoginActivity.class);
startActivity(intent);
finish();
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
} else
new LogoutTask().execute();
} else if (drawerItem.equals(ABOUT_ID)) {
if (!(BaseActivity.this instanceof AboutActivity)) {
Intent intent = new Intent(BaseActivity.this, AboutActivity.class);
startActivity(intent);
}
} else if (drawerItem.equals(SETTINGS_ID)) {
if (!(BaseActivity.this instanceof SettingsActivity)) {
Intent intent = new Intent(BaseActivity.this, SettingsActivity.class);
startActivity(intent);
}
drawer.closeDrawer();
return true;
}
drawer.closeDrawer();
return true;
});
if (sessionManager.isLoggedIn())
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem);
drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem);
else
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem);
drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem);
drawer = drawerBuilder.build();

58
app/src/main/java/gr/thmmy/mthmmy/viewmodel/ShoutboxViewModel.java

@ -0,0 +1,58 @@
package gr.thmmy.mthmmy.viewmodel;
import android.os.AsyncTask;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import gr.thmmy.mthmmy.activities.shoutbox.SendShoutTask;
import gr.thmmy.mthmmy.activities.shoutbox.ShoutboxTask;
import gr.thmmy.mthmmy.model.Shoutbox;
import gr.thmmy.mthmmy.session.SessionManager;
public class ShoutboxViewModel extends ViewModel {
private MutableLiveData<Shoutbox> shoutboxMutableLiveData = new MutableLiveData<>();
private ShoutboxTask shoutboxTask;
private ShoutboxTask.OnTaskStartedListener onShoutboxTaskStarted;
private ShoutboxTask.OnNetworkTaskFinishedListener<Shoutbox> onShoutboxTaskFinished;
private SendShoutTask.OnTaskStartedListener onSendShoutTaskStarted;
private SendShoutTask.OnNetworkTaskFinishedListener<Void> onSendShoutTaskFinished;
public void loadShoutbox() {
if (shoutboxTask != null && shoutboxTask.getStatus() == AsyncTask.Status.RUNNING)
shoutboxTask.cancel(true);
shoutboxTask = new ShoutboxTask(onShoutboxTaskStarted, onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
}
public void sendShout(String shout) {
if (shoutboxMutableLiveData.getValue() == null) throw new IllegalStateException("Shoutbox task has not finished yet!");
Shoutbox shoutbox = shoutboxMutableLiveData.getValue();
new SendShoutTask(onSendShoutTaskStarted, onSendShoutTaskFinished)
.execute(shoutbox.getSendShoutUrl(), shout, shoutbox.getSc(),
shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl());
}
public void setShoutbox(Shoutbox shoutbox) {
shoutboxMutableLiveData.setValue(shoutbox);
}
public MutableLiveData<Shoutbox> getShoutboxMutableLiveData() {
return shoutboxMutableLiveData;
}
public void setOnSendShoutTaskFinished(SendShoutTask.OnNetworkTaskFinishedListener<Void> onSendShoutTaskFinished) {
this.onSendShoutTaskFinished = onSendShoutTaskFinished;
}
public void setOnSendShoutTaskStarted(SendShoutTask.OnTaskStartedListener onSendShoutTaskStarted) {
this.onSendShoutTaskStarted = onSendShoutTaskStarted;
}
public void setOnShoutboxTaskFinished(ShoutboxTask.OnNetworkTaskFinishedListener<Shoutbox> onShoutboxTaskFinished) {
this.onShoutboxTaskFinished = onShoutboxTaskFinished;
}
public void setOnShoutboxTaskStarted(ShoutboxTask.OnTaskStartedListener onShoutboxTaskStarted) {
this.onShoutboxTaskStarted = onShoutboxTaskStarted;
}
}

16
app/src/main/res/drawable/refresh_label_background.xml

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="@color/accent" />
<solid android:color="@color/accent" />
<padding
android:left="1dp"
android:right="1dp"
android:bottom="1dp"
android:top="1dp" />
<corners android:radius="@dimen/refresh_label_border_radius" />
</shape>

32
app/src/main/res/layout/activity_shoutbox.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/ToolbarTheme">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:gravity="center"
app:popupTheme="@style/ToolbarTheme" />
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ShoutboxActivity" />
</LinearLayout>

32
app/src/main/res/layout/fragment_shoutbox.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -17,33 +16,12 @@
app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
<gr.thmmy.mthmmy.utils.CustomRecyclerView
android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<gr.thmmy.mthmmy.utils.CustomRecyclerView
android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/fragment_shoutbox_shout_row" />
<TextView
android:id="@+id/refresh_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="top"
android:layout_marginTop="4dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@drawable/refresh_label_background"
android:text="@string/refresh_button"
android:textColor="@color/primary_text" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
android:layout_weight="1"
tools:listitem="@layout/fragment_shoutbox_shout_row" />
<gr.thmmy.mthmmy.editorview.EditorView
android:id="@+id/edior_view"

Loading…
Cancel
Save