WIP
This commit is contained in:
parent
63b08fe718
commit
60791459c0
@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.navigation.NavController;
|
||||
@ -13,8 +14,10 @@ import it.danieleverducci.ojo.R;
|
||||
import it.danieleverducci.ojo.databinding.ActivityMainBinding;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
private ActivityMainBinding binding;
|
||||
private NavController navController;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -24,7 +27,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
// Show FAB only on first fragment
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
||||
navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
||||
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
|
||||
if (destination.getId() == R.id.HomeFragment)
|
||||
binding.fab.show();
|
||||
@ -35,8 +38,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
binding.fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
navController.navigate(R.id.action_homeToSettings);
|
||||
navigateToFragment(R.id.action_homeToSettings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void navigateToFragment(int actionId) {
|
||||
if (navController == null) {
|
||||
Log.e(TAG, "Not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
navController.navigate(actionId);
|
||||
}
|
||||
}
|
@ -55,6 +55,13 @@ public class SettingsFragment extends Fragment {
|
||||
touchHelper.attachToRecyclerView(recyclerView);
|
||||
adapter.setOnDragListener(touchHelper::startDrag);
|
||||
recyclerView.setAdapter(adapter);
|
||||
// Onclick listener
|
||||
adapter.setOnClickListener(new SettingsRecyclerViewAdapter.OnClickListener() {
|
||||
@Override
|
||||
public void onItemClick(Camera c) {
|
||||
((MainActivity)getActivity()).navigateToFragment(R.id.action_homeToSettings);
|
||||
}
|
||||
});
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter<SettingsRe
|
||||
|
||||
private final List<Camera> mValues;
|
||||
private OnDragListener dragListener;
|
||||
private OnClickListener clickListener;
|
||||
|
||||
public SettingsRecyclerViewAdapter(List<Camera> items) {
|
||||
mValues = items;
|
||||
@ -38,6 +39,12 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter<SettingsRe
|
||||
}
|
||||
return false;
|
||||
});
|
||||
vh.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
clickListener.onItemClick((Camera)view.getTag());
|
||||
}
|
||||
});
|
||||
return vh;
|
||||
}
|
||||
|
||||
@ -48,6 +55,8 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter<SettingsRe
|
||||
cameraName = holder.name.getContext().getString(R.string.stream_list_default_camera_name).replace("{camNo}", (position+1)+"");
|
||||
holder.name.setText(cameraName);
|
||||
holder.url.setText(mValues.get(position).getRtspUrl());
|
||||
// Save item
|
||||
holder.root.setTag(mValues.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,8 +94,12 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter<SettingsRe
|
||||
public void setOnDragListener(OnDragListener dragListener) {
|
||||
this.dragListener = dragListener;
|
||||
}
|
||||
public void setOnClickListener(OnClickListener clickListener) {
|
||||
this.clickListener = clickListener;
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public View root;
|
||||
public TextView name;
|
||||
public TextView url;
|
||||
public View dragHandle;
|
||||
@ -94,6 +107,7 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter<SettingsRe
|
||||
public ViewHolder(FragmentSettingsItemBinding binding) {
|
||||
super(binding.getRoot());
|
||||
|
||||
this.root = binding.getRoot();
|
||||
this.name = binding.cameraName;
|
||||
this.url = binding.cameraUrl;
|
||||
this.dragHandle = binding.cameraDragHandle;
|
||||
@ -103,4 +117,8 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter<SettingsRe
|
||||
public interface OnDragListener {
|
||||
void onItemDrag(ViewHolder vh);
|
||||
}
|
||||
|
||||
public interface OnClickListener {
|
||||
void onItemClick(Camera c);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user