added more options
This commit is contained in:
parent
7c2d662a19
commit
47ea1d6b8b
1 changed files with 104 additions and 92 deletions
|
@ -1,7 +1,5 @@
|
||||||
package code.name.monkey.retromusic.dialogs;
|
package code.name.monkey.retromusic.dialogs;
|
||||||
|
|
||||||
import static code.name.monkey.retromusic.Constants.USER_PROFILE;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
@ -11,11 +9,16 @@ import android.support.v7.widget.AppCompatTextView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
import code.name.monkey.retromusic.R;
|
import code.name.monkey.retromusic.R;
|
||||||
|
import code.name.monkey.retromusic.RetroApplication;
|
||||||
import code.name.monkey.retromusic.ui.activities.MainActivity;
|
import code.name.monkey.retromusic.ui.activities.MainActivity;
|
||||||
import code.name.monkey.retromusic.ui.fragments.mainactivity.folders.FoldersFragment;
|
import code.name.monkey.retromusic.ui.fragments.mainactivity.folders.FoldersFragment;
|
||||||
import code.name.monkey.retromusic.util.Compressor;
|
import code.name.monkey.retromusic.util.Compressor;
|
||||||
|
@ -26,109 +29,118 @@ import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import java.io.File;
|
|
||||||
import java.util.Calendar;
|
import static code.name.monkey.retromusic.Constants.USER_PROFILE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hemanth S (h4h13).
|
* @author Hemanth S (h4h13).
|
||||||
*/
|
*/
|
||||||
public class HomeOptionDialog extends RoundedBottomSheetDialogFragment {
|
public class HomeOptionDialog extends RoundedBottomSheetDialogFragment {
|
||||||
|
|
||||||
private static final String TAG = "HomeOptionDialog";
|
private static final String TAG = "HomeOptionDialog";
|
||||||
Unbinder mUnbinder;
|
Unbinder mUnbinder;
|
||||||
@BindView(R.id.user_image_bottom)
|
|
||||||
CircularImageView userImageBottom;
|
|
||||||
@BindView(R.id.title_welcome)
|
|
||||||
AppCompatTextView titleWelcome;
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
|
||||||
|
|
||||||
@Nullable
|
@BindView(R.id.user_image_bottom)
|
||||||
@Override
|
CircularImageView userImageBottom;
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
|
||||||
@Nullable Bundle savedInstanceState) {
|
|
||||||
View layout = inflater.inflate(R.layout.user_action_details, container, false);
|
|
||||||
mUnbinder = ButterKnife.bind(this, layout);
|
|
||||||
return layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@BindView(R.id.title_welcome)
|
||||||
|
AppCompatTextView titleWelcome;
|
||||||
|
|
||||||
@Override
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
loadImageFromStorage();
|
|
||||||
titleWelcome.setText(String.format("%s, %s!", getTimeOfTheDay(),
|
|
||||||
PreferenceUtil.getInstance(getContext()).getUserName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTimeOfTheDay() {
|
@Nullable
|
||||||
String message = getString(R.string.title_good_day);
|
@Override
|
||||||
Calendar c = Calendar.getInstance();
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
int timeOfDay = c.get(Calendar.HOUR_OF_DAY);
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
View layout = inflater.inflate(R.layout.user_action_details, container, false);
|
||||||
if (timeOfDay >= 0 && timeOfDay < 6) {
|
mUnbinder = ButterKnife.bind(this, layout);
|
||||||
message = getString(R.string.title_good_night);
|
layout.findViewById(R.id.action_buy_pro).setVisibility(RetroApplication.isProVersion() ? View
|
||||||
} else if (timeOfDay >= 6 && timeOfDay < 12) {
|
.GONE : View.VISIBLE);
|
||||||
message = getString(R.string.title_good_morning);
|
return layout;
|
||||||
} else if (timeOfDay >= 12 && timeOfDay < 16) {
|
|
||||||
message = getString(R.string.title_good_afternoon);
|
|
||||||
} else if (timeOfDay >= 16 && timeOfDay < 20) {
|
|
||||||
message = getString(R.string.title_good_evening);
|
|
||||||
} else if (timeOfDay >= 20 && timeOfDay < 24) {
|
|
||||||
message = getString(R.string.title_good_night);
|
|
||||||
}
|
}
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
disposable.clear();
|
|
||||||
mUnbinder.unbind();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@Override
|
||||||
@OnClick({R.id.action_about, R.id.user_info_container, R.id.action_folder, R.id.action_settings,
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
R.id.action_sleep_timer})
|
super.onViewCreated(view, savedInstanceState);
|
||||||
public void onViewClicked(View view) {
|
loadImageFromStorage();
|
||||||
switch (view.getId()) {
|
//noinspection ConstantConditions
|
||||||
case R.id.user_info_container:
|
titleWelcome.setText(String.format("%s, %s!", getTimeOfTheDay(),
|
||||||
NavigationUtil.goToUserInfo(getActivity());
|
PreferenceUtil.getInstance(getContext()).getUserName()));
|
||||||
break;
|
|
||||||
case R.id.action_folder:
|
|
||||||
MainActivity mainActivity = (MainActivity) getActivity();
|
|
||||||
if (mainActivity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mainActivity.setCurrentFragment(FoldersFragment.newInstance(getContext()), true);
|
|
||||||
break;
|
|
||||||
case R.id.action_settings:
|
|
||||||
NavigationUtil.goToSettings(getActivity());
|
|
||||||
break;
|
|
||||||
case R.id.action_about:
|
|
||||||
NavigationUtil.goToAbout(getActivity());
|
|
||||||
break;
|
|
||||||
case R.id.action_sleep_timer:
|
|
||||||
if (getFragmentManager() != null) {
|
|
||||||
new SleepTimerDialog().show(getFragmentManager(), TAG);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadImageFromStorage() {
|
private String getTimeOfTheDay() {
|
||||||
//noinspection ConstantConditions
|
String message = getString(R.string.title_good_day);
|
||||||
disposable.add(new Compressor(getContext())
|
Calendar c = Calendar.getInstance();
|
||||||
.setMaxHeight(300)
|
int timeOfDay = c.get(Calendar.HOUR_OF_DAY);
|
||||||
.setMaxWidth(300)
|
|
||||||
.setQuality(75)
|
if (timeOfDay >= 0 && timeOfDay < 6) {
|
||||||
.setCompressFormat(Bitmap.CompressFormat.WEBP)
|
message = getString(R.string.title_good_night);
|
||||||
.compressToBitmapAsFlowable(
|
} else if (timeOfDay >= 6 && timeOfDay < 12) {
|
||||||
new File(PreferenceUtil.getInstance(getContext()).getProfileImage(), USER_PROFILE))
|
message = getString(R.string.title_good_morning);
|
||||||
.subscribeOn(Schedulers.io())
|
} else if (timeOfDay >= 12 && timeOfDay < 16) {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
message = getString(R.string.title_good_afternoon);
|
||||||
.subscribe(userImageBottom::setImageBitmap,
|
} else if (timeOfDay >= 16 && timeOfDay < 20) {
|
||||||
throwable -> userImageBottom.setImageDrawable(ContextCompat
|
message = getString(R.string.title_good_evening);
|
||||||
.getDrawable(getContext(), R.drawable.ic_person_flat))));
|
} else if (timeOfDay >= 20 && timeOfDay < 24) {
|
||||||
}
|
message = getString(R.string.title_good_night);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
disposable.clear();
|
||||||
|
mUnbinder.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@OnClick({R.id.action_about, R.id.user_info_container, R.id.action_buy_pro, R.id.action_folder,
|
||||||
|
R.id.action_settings, R.id.action_sleep_timer})
|
||||||
|
public void onViewClicked(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.user_info_container:
|
||||||
|
NavigationUtil.goToUserInfo(getActivity());
|
||||||
|
break;
|
||||||
|
case R.id.action_folder:
|
||||||
|
MainActivity mainActivity = (MainActivity) getActivity();
|
||||||
|
if (mainActivity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mainActivity.setCurrentFragment(FoldersFragment.newInstance(getContext()), true);
|
||||||
|
break;
|
||||||
|
case R.id.action_settings:
|
||||||
|
NavigationUtil.goToSettings(getActivity());
|
||||||
|
break;
|
||||||
|
case R.id.action_about:
|
||||||
|
NavigationUtil.goToAbout(getActivity());
|
||||||
|
break;
|
||||||
|
case R.id.action_buy_pro:
|
||||||
|
NavigationUtil.goToProVersion(getActivity());
|
||||||
|
break;
|
||||||
|
case R.id.action_sleep_timer:
|
||||||
|
if (getFragmentManager() != null) {
|
||||||
|
new SleepTimerDialog().show(getFragmentManager(), TAG);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadImageFromStorage() {
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
disposable.add(new Compressor(getContext())
|
||||||
|
.setMaxHeight(300)
|
||||||
|
.setMaxWidth(300)
|
||||||
|
.setQuality(75)
|
||||||
|
.setCompressFormat(Bitmap.CompressFormat.WEBP)
|
||||||
|
.compressToBitmapAsFlowable(
|
||||||
|
new File(PreferenceUtil.getInstance(getContext()).getProfileImage(), USER_PROFILE))
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(userImageBottom::setImageBitmap,
|
||||||
|
throwable -> userImageBottom.setImageDrawable(ContextCompat
|
||||||
|
.getDrawable(getContext(), R.drawable.ic_person_flat))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue