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. 32
      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. 28
      app/src/main/res/layout/fragment_shoutbox.xml

3
app/build.gradle

@ -40,7 +40,7 @@ tasks.whenTaskAdded { task ->
task.getDependsOn().add({ task.getDependsOn().add({
def inputFile = new File("app/google-services.json") def inputFile = new File("app/google-services.json")
def json = new JsonSlurper().parseText(inputFile.text) 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!') 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 'net.gotev:uploadservice-okhttp:3.4.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'com.google.android.material:material:1.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' apply plugin: 'com.google.gms.google-services'

8
app/src/main/AndroidManifest.xml

@ -154,6 +154,14 @@
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:parentActivityName=".activities.main.MainActivity" android:parentActivityName=".activities.main.MainActivity"
android:theme="@style/AppTheme.NoActionBar" /> 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> </application>
</manifest> </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.downloads.DownloadsActivity;
import gr.thmmy.mthmmy.activities.main.forum.ForumFragment; import gr.thmmy.mthmmy.activities.main.forum.ForumFragment;
import gr.thmmy.mthmmy.activities.main.recent.RecentFragment; 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.main.unread.UnreadFragment;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity; import gr.thmmy.mthmmy.activities.settings.SettingsActivity;
@ -79,10 +78,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT");
sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM"); sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM");
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn())
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD");
sectionsPagerAdapter.addFragment(ShoutboxFragment.newInstance(4), "SHOUTBOX");
}
//Set up the ViewPager with the sections adapter. //Set up the ViewPager with the sections adapter.
viewPager = findViewById(R.id.container); 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)); tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_forum_white_24dp));
}else if (i == 2) { }else if (i == 2) {
tabLayout.getTabAt(i).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); 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() { public void updateTabs() {
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 4) { if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) {
sectionsPagerAdapter.removeFragment(3);
sectionsPagerAdapter.removeFragment(2); sectionsPagerAdapter.removeFragment(2);
} }
else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) { else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) {
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); 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(3).setIcon(R.drawable.ic_fiber_new_white_24dp);
tabLayout.getTabAt(4).setIcon(R.drawable.ic_announcement);
} }
} }
//-------------------------------FragmentPagerAdapter END------------------------------------------- //-------------------------------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; 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.annotation.TargetApi;
import android.content.Context; 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.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -8,16 +7,14 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; 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.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.editorview.EditorView; import gr.thmmy.mthmmy.editorview.EditorView;
import gr.thmmy.mthmmy.editorview.EmojiKeyboard; import gr.thmmy.mthmmy.editorview.EmojiKeyboard;
import gr.thmmy.mthmmy.model.Shout; 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.session.SessionManager;
import gr.thmmy.mthmmy.utils.CustomRecyclerView; import gr.thmmy.mthmmy.utils.CustomRecyclerView;
import gr.thmmy.mthmmy.utils.NetworkResultCodes; import gr.thmmy.mthmmy.utils.NetworkResultCodes;
import gr.thmmy.mthmmy.viewmodel.ShoutboxViewModel;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import timber.log.Timber; import timber.log.Timber;
public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.EmojiKeyboardOwner { public class ShoutboxFragment extends Fragment implements EmojiKeyboard.EmojiKeyboardOwner {
private static final String TAG = "ShoutboxFragment";
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private TextView refreshLabel;
private ShoutboxTask shoutboxTask; private ShoutboxTask shoutboxTask;
private ShoutAdapter shoutAdapter; private ShoutAdapter shoutAdapter;
private EmojiKeyboard emojiKeyboard; private EmojiKeyboard emojiKeyboard;
private EditorView editorView; 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) { private ShoutboxViewModel mViewModel;
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 void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { public static ShoutboxFragment newInstance() {
progressBar.setVisibility(View.INVISIBLE); return new ShoutboxFragment();
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();
}
} }
@Nullable @Nullable
@Override @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); 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); progressBar = rootView.findViewById(R.id.progressBar);
CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview); CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview);
shoutAdapter = new ShoutAdapter(getContext(), new Shout[0]); shoutAdapter = new ShoutAdapter(getContext(), new Shout[0]);
@ -117,19 +59,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0);
return false; 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); emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard);
editorView = rootView.findViewById(R.id.edior_view); editorView = rootView.findViewById(R.id.edior_view);
@ -137,17 +66,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
InputConnection ic = editorView.getInputConnection(); InputConnection ic = editorView.getInputConnection();
setEmojiKeyboardInputConnection(ic); setEmojiKeyboardInputConnection(ic);
editorView.setOnSubmitListener(view -> { editorView.setOnSubmitListener(view -> {
if (shoutbox == null) return; if (mViewModel.getShoutboxMutableLiveData().getValue() == null) return;
if (editorView.getText().toString().isEmpty()) { if (editorView.getText().toString().isEmpty()) {
editorView.setError("Required"); editorView.setError("Required");
return; return;
} }
editorView.setAlpha(0.5f); mViewModel.sendShout(editorView.getText().toString());
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());
}); });
editorView.hideMarkdown(); editorView.hideMarkdown();
editorView.setOnTouchListener((view, motionEvent) -> { editorView.setOnTouchListener((view, motionEvent) -> {
@ -160,30 +84,64 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
return rootView; return rootView;
} }
private void hideRefreshLabel() { @Override
if (refreshLabel.getVisibility() == View.GONE) return; public void onActivityCreated(@Nullable Bundle savedInstanceState) {
if (animator != null) animator.cancel(); super.onActivityCreated(savedInstanceState);
animator = getRefreshLabelAnimation(); mViewModel = ViewModelProviders.of(this).get(ShoutboxViewModel.class);
animator.start(); 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);
private void showRefreshLabel() { mViewModel.loadShoutbox();
if (refreshLabel.getVisibility() == View.VISIBLE) return;
if (animator != null) animator.cancel();
animator = getRefreshLabelAnimation();
animator.reverse();
} }
private ValueAnimator getRefreshLabelAnimation() { private void onShoutboxTaskSarted() {
ValueAnimator animator = ValueAnimator.ofFloat(-200, 0); Timber.i("Starting shoutbox task...");
animator.addUpdateListener(valueAnimator -> { progressBar.setVisibility(View.VISIBLE);
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()); private void onSendShoutTaskStarted() {
}); Timber.i("Start sending a shout...");
animator.setInterpolator(new FastOutSlowInInterpolator()); editorView.setAlpha(0.5f);
animator.setDuration(200); editorView.setEnabled(false);
return animator; 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 @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.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;

32
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.main.MainActivity;
import gr.thmmy.mthmmy.activities.profile.ProfileActivity; import gr.thmmy.mthmmy.activities.profile.ProfileActivity;
import gr.thmmy.mthmmy.activities.settings.SettingsActivity; 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.activities.upload.UploadActivity;
import gr.thmmy.mthmmy.model.Bookmark; import gr.thmmy.mthmmy.model.Bookmark;
import gr.thmmy.mthmmy.model.ThmmyFile; 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 LOG_ID = 4;
protected static final int ABOUT_ID = 5; protected static final int ABOUT_ID = 5;
protected static final int SETTINGS_ID = 6; protected static final int SETTINGS_ID = 6;
protected static final int SHOUTBOX_ID = 7;
private AccountHeader accountHeader; private AccountHeader accountHeader;
private ProfileDrawerItem profileDrawerItem; 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 selectedPrimaryColor = ContextCompat.getColor(this, R.color.primary_dark);
final int selectedSecondaryColor = ContextCompat.getColor(this, R.color.accent); 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, IconicsDrawable homeIcon, homeIconSelected, downloadsIcon, downloadsIconSelected, uploadIcon, uploadIconSelected, settingsIcon,
settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected; settingsIconSelected, bookmarksIcon, bookmarksIconSelected, aboutIcon, aboutIconSelected;
@ -230,6 +232,15 @@ public abstract class BaseActivity extends AppCompatActivity {
.withIcon(homeIcon) .withIcon(homeIcon)
.withSelectedIcon(homeIconSelected); .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 if (sessionManager.isLoggedIn()) //When logged in
{ {
@ -301,9 +312,7 @@ public abstract class BaseActivity extends AppCompatActivity {
.withSelectionListEnabledForSingleProfile(false) .withSelectionListEnabledForSingleProfile(false)
.withHeaderBackground(R.color.primary) .withHeaderBackground(R.color.primary)
.addProfiles(profileDrawerItem) .addProfiles(profileDrawerItem)
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { .withOnAccountHeaderListener((view, profile, currentProfile) -> {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn()) {
Intent intent = new Intent(BaseActivity.this, ProfileActivity.class); Intent intent = new Intent(BaseActivity.this, ProfileActivity.class);
Bundle extras = new Bundle(); Bundle extras = new Bundle();
@ -320,7 +329,6 @@ public abstract class BaseActivity extends AppCompatActivity {
} }
return true; return true;
}
}) })
.build(); .build();
@ -331,14 +339,17 @@ public abstract class BaseActivity extends AppCompatActivity {
.withDrawerWidthDp((int) BaseApplication.getInstance().getDpWidth() / 2) .withDrawerWidthDp((int) BaseApplication.getInstance().getDpWidth() / 2)
.withSliderBackgroundColor(ContextCompat.getColor(this, R.color.primary_light)) .withSliderBackgroundColor(ContextCompat.getColor(this, R.color.primary_light))
.withAccountHeader(accountHeader) .withAccountHeader(accountHeader)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { .withOnDrawerItemClickListener((view, position, drawerItem) -> {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem.equals(HOME_ID)) { if (drawerItem.equals(HOME_ID)) {
if (!(BaseActivity.this instanceof MainActivity)) { if (!(BaseActivity.this instanceof MainActivity)) {
Intent intent = new Intent(BaseActivity.this, MainActivity.class); Intent intent = new Intent(BaseActivity.this, MainActivity.class);
startActivity(intent); 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)) { } else if (drawerItem.equals(DOWNLOADS_ID)) {
if (!(BaseActivity.this instanceof DownloadsActivity)) { if (!(BaseActivity.this instanceof DownloadsActivity)) {
Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class); Intent intent = new Intent(BaseActivity.this, DownloadsActivity.class);
@ -381,13 +392,12 @@ public abstract class BaseActivity extends AppCompatActivity {
drawer.closeDrawer(); drawer.closeDrawer();
return true; return true;
}
}); });
if (sessionManager.isLoggedIn()) if (sessionManager.isLoggedIn())
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, downloadsItem, uploadItem, settingsItem, loginLogoutItem, aboutItem);
else else
drawerBuilder.addDrawerItems(homeItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem); drawerBuilder.addDrawerItems(homeItem, shoutboxItem, bookmarksItem, settingsItem, loginLogoutItem, aboutItem);
drawer = drawerBuilder.build(); 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>

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

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -17,34 +16,13 @@
app:mpb_indeterminateTint="@color/accent" app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal" /> app:mpb_progressStyle="horizontal" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<gr.thmmy.mthmmy.utils.CustomRecyclerView <gr.thmmy.mthmmy.utils.CustomRecyclerView
android:id="@+id/shoutbox_recyclerview" android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_weight="1"
tools:listitem="@layout/fragment_shoutbox_shout_row" /> 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>
<gr.thmmy.mthmmy.editorview.EditorView <gr.thmmy.mthmmy.editorview.EditorView
android:id="@+id/edior_view" android:id="@+id/edior_view"
android:layout_width="match_parent" android:layout_width="match_parent"

Loading…
Cancel
Save