Starting with popup menus on home view
This commit is contained in:
parent
726ba9cda5
commit
be24625c2d
|
|
@ -4,7 +4,7 @@
|
||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2024-12-15T22:57:07.275689656Z">
|
<DropdownSelection timestamp="2024-12-15T23:09:00.427909866Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="LocalEmulator" identifier="path=/home/nicolas/.android/avd/Pixel_6_Pro_API_34.avd" />
|
<DeviceId pluginId="LocalEmulator" identifier="path=/home/nicolas/.android/avd/Pixel_6_Pro_API_34.avd" />
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.example.dcav2gui.ui.home;
|
package com.example.dcav2gui.ui.home;
|
||||||
|
|
||||||
import static androidx.core.content.res.ResourcesCompat.getColor;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
@ -11,13 +9,17 @@ import android.text.SpannableString;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.PopupMenu;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -28,6 +30,7 @@ import com.example.dcav2gui.InstanceInterface;
|
||||||
import com.example.dcav2gui.MainActivity;
|
import com.example.dcav2gui.MainActivity;
|
||||||
import com.example.dcav2gui.R;
|
import com.example.dcav2gui.R;
|
||||||
import com.example.dcav2gui.TickerTracker;
|
import com.example.dcav2gui.TickerTracker;
|
||||||
|
import com.example.dcav2gui.databinding.FragmentHomeBinding;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -43,7 +46,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
public class HomeFragment extends Fragment {
|
public class HomeFragment extends Fragment {
|
||||||
private HomeViewModel homeViewModel;
|
private HomeViewModel homeViewModel;
|
||||||
//private FragmentHomeBinding binding;
|
private FragmentHomeBinding binding;
|
||||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
private Handler handler = new Handler();
|
private Handler handler = new Handler();
|
||||||
|
|
@ -53,6 +56,7 @@ public class HomeFragment extends Fragment {
|
||||||
private TextView progressBarText;
|
private TextView progressBarText;
|
||||||
private ScrollView mainHomeScrollView;
|
private ScrollView mainHomeScrollView;
|
||||||
|
|
||||||
|
|
||||||
//Tickers
|
//Tickers
|
||||||
private TextView pricePair1;
|
private TextView pricePair1;
|
||||||
private TextView pricePair124hPercentage ;
|
private TextView pricePair124hPercentage ;
|
||||||
|
|
@ -118,8 +122,8 @@ public class HomeFragment extends Fragment {
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
//binding = FragmentHomeBinding.inflate(inflater, container, false);
|
// binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||||
//View root = binding.getRoot();
|
// View root = binding.getRoot();
|
||||||
|
|
||||||
|
|
||||||
// For the cache
|
// For the cache
|
||||||
|
|
@ -133,6 +137,16 @@ public class HomeFragment extends Fragment {
|
||||||
progressBarText = root.findViewById(R.id.progressBarText);
|
progressBarText = root.findViewById(R.id.progressBarText);
|
||||||
mainHomeScrollView = root.findViewById(R.id.mainHomeScrollView);
|
mainHomeScrollView = root.findViewById(R.id.mainHomeScrollView);
|
||||||
|
|
||||||
|
LinearLayout todayThisMonthCard = root.findViewById(R.id.todayThisMonthCard);
|
||||||
|
LinearLayout exchange1View = root.findViewById(R.id.exchangeStats1Card);
|
||||||
|
LinearLayout exchange2View = root.findViewById(R.id.exchangeStats2Card);
|
||||||
|
LinearLayout exchange3View = root.findViewById(R.id.exchangeStats3Card);
|
||||||
|
LinearLayout exchange4View = root.findViewById(R.id.exchangeStats4Card);
|
||||||
|
LinearLayout log1View = root.findViewById(R.id.log1Card);
|
||||||
|
LinearLayout log2View = root.findViewById(R.id.log2Card);
|
||||||
|
LinearLayout log3View = root.findViewById(R.id.log3Card);
|
||||||
|
LinearLayout log4View = root.findViewById(R.id.log4Card);
|
||||||
|
|
||||||
// Bind text views
|
// Bind text views
|
||||||
// Tickers
|
// Tickers
|
||||||
pricePair1 = root.findViewById(R.id.pricesCardPrice1);
|
pricePair1 = root.findViewById(R.id.pricesCardPrice1);
|
||||||
|
|
@ -213,81 +227,88 @@ public class HomeFragment extends Fragment {
|
||||||
homeViewCache.getGateioLogs(),
|
homeViewCache.getGateioLogs(),
|
||||||
homeViewCache.getKucoinLogs(),
|
homeViewCache.getKucoinLogs(),
|
||||||
homeViewCache.getOkexLogs());
|
homeViewCache.getOkexLogs());
|
||||||
|
|
||||||
} else {
|
|
||||||
//Prices
|
|
||||||
pricePair1.setText(R.string.default_price_ticker_1);
|
|
||||||
pricePair2.setText(R.string.default_price_ticker_2);
|
|
||||||
pricePair3.setText(R.string.default_price_ticker_3);
|
|
||||||
|
|
||||||
|
|
||||||
pricePair124hPercentage.setText(R.string.percentage_example);
|
|
||||||
pricePair17dPercentage.setText(R.string.percentage_example);
|
|
||||||
pricePair130dPercentage.setText(R.string.percentage_example);
|
|
||||||
|
|
||||||
pricePair224hPercentage.setText(R.string.percentage_example);
|
|
||||||
pricePair27dPercentage.setText(R.string.percentage_example);
|
|
||||||
pricePair230dPercentage.setText(R.string.percentage_example);
|
|
||||||
|
|
||||||
pricePair324hPercentage.setText(R.string.percentage_example);
|
|
||||||
pricePair37dPercentage.setText(R.string.percentage_example);
|
|
||||||
pricePair330dPercentage.setText(R.string.percentage_example);
|
|
||||||
|
|
||||||
|
|
||||||
pricePair124hPercentage.setTextColor(Color.GREEN);
|
|
||||||
pricePair17dPercentage.setTextColor(Color.GREEN);
|
|
||||||
pricePair130dPercentage.setTextColor(Color.GREEN);
|
|
||||||
|
|
||||||
pricePair224hPercentage.setTextColor(Color.GREEN);
|
|
||||||
pricePair27dPercentage.setTextColor(Color.GREEN);
|
|
||||||
pricePair230dPercentage.setTextColor(Color.GREEN);
|
|
||||||
|
|
||||||
pricePair324hPercentage.setTextColor(Color.GREEN);
|
|
||||||
pricePair37dPercentage.setTextColor(Color.GREEN);
|
|
||||||
pricePair330dPercentage.setTextColor(Color.GREEN);
|
|
||||||
|
|
||||||
|
|
||||||
// Profits today and this month
|
|
||||||
profitsToday.setText(R.string.profits_today_example);
|
|
||||||
profitsThisMonth.setText(R.string.profits_this_month_example);
|
|
||||||
|
|
||||||
|
|
||||||
//Exchange status
|
|
||||||
exchange1Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
||||||
exchange2Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
||||||
exchange3Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
||||||
exchange4Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
||||||
|
|
||||||
exchange1Funds.setText(R.string.exchange_funds_example);
|
|
||||||
exchange2Funds.setText(R.string.exchange_funds_example);
|
|
||||||
exchange3Funds.setText(R.string.exchange_funds_example);
|
|
||||||
exchange4Funds.setText(R.string.exchange_funds_example);
|
|
||||||
|
|
||||||
exchange1FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
||||||
exchange2FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
||||||
exchange3FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
||||||
exchange4FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
||||||
|
|
||||||
exchange1WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
||||||
exchange2WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
||||||
exchange3WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
||||||
exchange4WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
||||||
|
|
||||||
exchange1WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
||||||
exchange2WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
||||||
exchange3WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
||||||
exchange4WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
||||||
|
|
||||||
// Last trades
|
|
||||||
lastTrades.setText(R.string.last_trades_example);
|
|
||||||
|
|
||||||
// Log entries
|
|
||||||
log1Content.setText(R.string.log_example);
|
|
||||||
log2Content.setText(R.string.log_example);
|
|
||||||
log3Content.setText(R.string.log_example);
|
|
||||||
log4Content.setText(R.string.log_example);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Listener for priceCard
|
||||||
|
todayThisMonthCard.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showTodayThisMonthPopupMenu(v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Listener for exchanges card
|
||||||
|
exchange1View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showExchangePopupMenu(v, "binance");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
exchange2View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showExchangePopupMenu(v, "gateio");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
exchange3View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showExchangePopupMenu(v, "kucoin");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//Listener for exchanges card
|
||||||
|
exchange4View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showExchangePopupMenu(v, "okex");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Listener for last deals
|
||||||
|
lastTrades.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showLastTradesPopupMenu(v);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Listener for log views
|
||||||
|
log1View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showLogPopupMenu(v, "binance");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
log2View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showLogPopupMenu(v, "gateio");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
log3View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showLogPopupMenu(v, "kucoin");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
log4View.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
showLogPopupMenu(v, "okex");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Setup task
|
// Setup task
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
updateRunnable = new Runnable() {
|
updateRunnable = new Runnable() {
|
||||||
|
|
@ -306,6 +327,81 @@ public class HomeFragment extends Fragment {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void showTodayThisMonthPopupMenu(View anchorView) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
||||||
|
popupMenu.getMenuInflater().inflate(R.menu.today_this_month_menu, popupMenu.getMenu());
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getItemId() == R.id.today_this_month_details) {
|
||||||
|
// Handle the "Details..." option
|
||||||
|
// For example, navigate to a details fragment
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showExchangePopupMenu(View anchorView, String exchange) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
||||||
|
popupMenu.getMenuInflater().inflate(R.menu.exchange_popup_menu, popupMenu.getMenu());
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getItemId() == R.id.exchangeStatus) {
|
||||||
|
// Handle the "Details..." option
|
||||||
|
// For example, navigate to a details fragment
|
||||||
|
return true;
|
||||||
|
} else if (item.getItemId() == R.id.exchangeCommands) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLastTradesPopupMenu(View anchorView) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
||||||
|
popupMenu.getMenuInflater().inflate(R.menu.last_trades_menu, popupMenu.getMenu());
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getItemId() == R.id.last_trades_details) {
|
||||||
|
// Handle the "Details..." option
|
||||||
|
// For example, navigate to a details fragment
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLogPopupMenu(View anchorView, String exchange) {
|
||||||
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
||||||
|
popupMenu.getMenuInflater().inflate(R.menu.logs_menu, popupMenu.getMenu());
|
||||||
|
|
||||||
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getItemId() == R.id.log_details) {
|
||||||
|
// Handle the "Details..." option
|
||||||
|
// For example, navigate to a details fragment
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popupMenu.show();
|
||||||
|
}
|
||||||
|
|
||||||
// Adds a plus sign if the percentage is positive
|
// Adds a plus sign if the percentage is positive
|
||||||
private String formatPercentage(double value) {
|
private String formatPercentage(double value) {
|
||||||
if (value>=0) {
|
if (value>=0) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/exchangeStatus"
|
||||||
|
android:title="Status">
|
||||||
|
<menu>
|
||||||
|
<item android:id="@+id/status1"
|
||||||
|
android:title="Status 1" />
|
||||||
|
<item android:id="@+id/status2"
|
||||||
|
android:title="Status 2" />
|
||||||
|
<item android:id="@+id/status3"
|
||||||
|
android:title="Status 3" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
android:id="@+id/exchangeCommands"
|
||||||
|
android:title="Commands">
|
||||||
|
<menu>
|
||||||
|
<item android:id="@+id/command1"
|
||||||
|
android:title="Command 1" />
|
||||||
|
<item android:id="@+id/command2"
|
||||||
|
android:title="Command 2" />
|
||||||
|
<item android:id="@+id/command3"
|
||||||
|
android:title="Command 3" />
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
|
</menu>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/last_trades_details"
|
||||||
|
android:title="More..." />
|
||||||
|
</menu>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/log_details"
|
||||||
|
android:title="Details..." />
|
||||||
|
</menu>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:id="@+id/today_this_month_details"
|
||||||
|
android:title="Details..." />
|
||||||
|
</menu>
|
||||||
Loading…
Reference in New Issue