Skip to content

Commit

Permalink
Merge branch 'Settings' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
npofsi committed Oct 2, 2021
2 parents b924571 + 46de69f commit 31cbcba
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cn.settile.fanboxviewer.Fragments

import android.os.Bundle
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import cn.settile.fanboxviewer.R

class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
savedInstanceState?.get("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;

import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
Expand Down Expand Up @@ -39,8 +41,7 @@ public PostFragment() {
}

public static PostFragment newInstance() {
PostFragment fragment = new PostFragment();
return fragment;
return new PostFragment();
}

@Override
Expand Down
28 changes: 22 additions & 6 deletions app/src/main/java/cn/settile/fanboxviewer/ImageViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import android.app.DownloadManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import androidx.palette.graphics.Palette;
import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand Down Expand Up @@ -39,6 +41,9 @@ public class ImageViewActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_view);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
boolean loadThumb = sp.getBoolean("display_thumb", true);
boolean dlThumb = sp.getBoolean("download_thumb", false);

Intent i = getIntent();
this.images = i.getStringArrayListExtra("Images");
Expand All @@ -62,19 +67,24 @@ protected void onCreate(Bundle savedInstanceState) {
String extension = images.get(position)
.substring(images.get(position).lastIndexOf('.'));
String name = detail + "_" + position + extension;
new DownloadRequestor((DownloadManager) getSystemService(DOWNLOAD_SERVICE))
.downloadWithCookie(images.get(position), name, Constants.Cookie);
if (dlThumb)
new DownloadRequestor((DownloadManager) getSystemService(DOWNLOAD_SERVICE))
.downloadWithCookie(thumbs.get(position), name, Constants.Cookie);
else
new DownloadRequestor((DownloadManager) getSystemService(DOWNLOAD_SERVICE))
.downloadWithCookie(images.get(position), name, Constants.Cookie);
} catch (Exception ex) {
Log.e(TAG, "onCreate: ", ex);
}
})
.setFragmentManager(getSupportFragmentManager());
CustomPicassoLoader mi;
for (int index = 0; index < images.size(); index++) {
CustomPicassoLoader mi = new CustomPicassoLoader(this, thumbs.get(index));


if (loadThumb)
mi = new CustomPicassoLoader(this, thumbs.get(index));
else
mi = new CustomPicassoLoader(this, images.get(index));
final int index1 = index;

mi.onLoaded((b) -> {
colors.set(index1,
Palette.from(toBitmap(b))
Expand All @@ -86,8 +96,14 @@ protected void onCreate(Bundle savedInstanceState) {
);
}
view.setCurrentItem(pos);
view.invalidate();
new Thread(() -> {
while (colors.size() - 1 < pos) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
view.setBackgroundColor(colors.get(pos));
view.invalidate();
Expand Down
78 changes: 43 additions & 35 deletions app/src/main/java/cn/settile/fanboxviewer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavDestination;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.navigation.NavigationView;
import com.squareup.picasso.Picasso;

import org.jetbrains.annotations.Contract;

import java.util.Objects;

import cn.settile.fanboxviewer.Fragments.SettingsFragment;
import cn.settile.fanboxviewer.ViewComponents.LogoutDialog;
import cn.settile.fanboxviewer.ViewModels.MainViewModel;

Expand All @@ -43,22 +39,20 @@ public class MainActivity extends AppCompatActivity
MainActivity ctx = null;

NavController navController;
private NavHostFragment navHostFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ctx = this;

setContentView(R.layout.activity_main);


prepareUIAndActions();

setTitle(R.string.app_name);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);

Expand All @@ -74,7 +68,8 @@ protected void onCreate(Bundle savedInstanceState) {
//navigationView.getMenu().getItem(1).setEnabled(true);

setResult(-1);
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_main);
navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment_main);
assert navHostFragment != null;
navController = navHostFragment.getNavController();
NavigationUI.setupWithNavController(navigationView, navController);

Expand All @@ -84,24 +79,18 @@ protected void onCreate(Bundle savedInstanceState) {
.build();


navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller,
@NonNull NavDestination destination, @Nullable Bundle arguments) {
//navHostFragment.getNavController().navigateUp();
Log.d(TAG, destination.getLabel().toString());
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
//navHostFragment.getNavController().navigateUp();
Log.d(TAG, destination.getLabel().toString());

}
});

}


void prepareUIAndActions() {

viewModel = new ViewModelProvider(this).get(MainViewModel.class);


viewModel.is_logged_in().observe(this, (it) -> {
Log.i(TAG, it.toString());
NavigationView navV = (NavigationView) ctx.findViewById(R.id.nav_view);
Expand All @@ -128,16 +117,15 @@ void prepareUIAndActions() {
});

viewModel.getUser_icon_url().observe(this, (it) -> {
if (!Objects.equals(it, "")) Picasso.get()
if (!Objects.equals(it, ""))
Picasso.get()
.load(it)
.placeholder(R.drawable.ic_settings_system_daydream_black_24dp)
.resize(180, 180)
.into((ImageView) findViewById(R.id.userIcon));
});
}

;


@Override
public void onBackPressed() {
Expand All @@ -157,6 +145,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
Expand All @@ -166,6 +155,13 @@ public boolean onOptionsItemSelected(MenuItem item) {

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
SettingsFragment sf = new SettingsFragment();
ft.replace(R.id.mainTabFragment, sf);
ft.commit();
if (getSupportActionBar() != null){
getSupportActionBar().setTitle(R.string.action_settings);
}
return true;
} else if (id == R.id.action_refresh) {
return true;
Expand All @@ -174,6 +170,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}


@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Expand All @@ -184,47 +181,58 @@ public boolean onNavigationItemSelected(MenuItem item) {
//Toast.makeText(this, "HOME", Toast.LENGTH_SHORT).show();
} else if (id == R.id.nav_supporting) {
//Toast.makeText(this, "Fan Cards", Toast.LENGTH_SHORT).show();

} else if (id == R.id.nav_search) {
Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
// Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
} else if (id == R.id.nav_settings) {
//TODO (SettingsActivity)
//callSettings();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
SettingsFragment sf = new SettingsFragment();
ft.replace(R.id.mainTabFragment, sf);
ft.commit();
if (getSupportActionBar() != null){
getSupportActionBar().setTitle(R.string.action_settings);
}
} else if (id == R.id.nav_logout) {
//Toast.makeText(this, "Logout", Toast.LENGTH_SHORT).show();
new LogoutDialog(this).show();
} else if (id == R.id.nav_recommend) {
Toast.makeText(this, "Recommended", Toast.LENGTH_SHORT).show();
// Toast.makeText(this, "Recommended", Toast.LENGTH_SHORT).show();
}

drawer.closeDrawer(GravityCompat.START);
return true;
}

private void closeDrawer(){
DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (Objects.nonNull(drawer))
drawer.closeDrawer(GravityCompat.START);
}

//UICalls
public void toSupportingFragment(MenuItem v) {
if (navController.getCurrentDestination().getId() != R.id.supportingFragment)
navController.navigate(R.id.supportingFragment);
closeDrawer();
}

public void toMainTabFragment(MenuItem v) {
if (navController.getCurrentDestination().getId() != R.id.mainTabFragment)
navController.navigate(R.id.mainTabFragment);
closeDrawer();
}

public void toSettingsFragment(MenuItem v) {
if (navController.getCurrentDestination().getId() != R.id.settingsFragment)
navController.navigate(R.id.settingsFragment);
closeDrawer();
}

public void callLogout(MenuItem v) {
public void openLogoutDialog(MenuItem ignored){
new LogoutDialog(this).show();
}

@Contract("_->null")

public void callLogin() {
Intent intent = new Intent(this, LoginActivity.class);
if (!viewModel.is_logged_in().getValue()) startActivityForResult(intent, -1);
}

public void callSettings() {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cn.settile.fanboxviewer

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceFragmentCompat
import cn.settile.fanboxviewer.Fragments.SettingsFragment

class SettingsActivity : AppCompatActivity() {

Expand All @@ -17,11 +17,4 @@ class SettingsActivity : AppCompatActivity() {
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}

class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
//TODO
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/cn/settile/fanboxviewer/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;

import org.jetbrains.annotations.NotNull;

Expand All @@ -44,6 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

PreferenceManager.setDefaultValues(this , R.xml.root_preferences , false);
setTitle(R.string.loading);
prepareUIAndActions();
if (ContextCompat.checkSelfPermission(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/menu/activity_drawer_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_menu_manage"
android:onClick="toSettingsFragment"
android:title="@string/menu_tools" />
<item
android:id="@+id/nav_logout"
android:icon="@drawable/ic_menu_send"
android:onClick="callLogout"
android:onClick="openLogoutDialog"
android:title="@string/menu_logout" />
</menu>
</item>
Expand Down
Loading

0 comments on commit 31cbcba

Please sign in to comment.