ui优化
This commit is contained in:
parent
b1f86a18a6
commit
838114d58d
@ -0,0 +1,7 @@
|
||||
package com.example.funnysounds.action;
|
||||
|
||||
import com.example.funnysounds.data.MyData;
|
||||
|
||||
public interface IOListener {
|
||||
public void onRunIOAction( );
|
||||
}
|
||||
@ -91,7 +91,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
setTabSelected(tab, true);
|
||||
vb.viewPager.setCurrentItem(tab.getPosition());
|
||||
int position = tab.getPosition();
|
||||
vb.viewPager.setCurrentItem(position);
|
||||
updateTitle(position);
|
||||
|
||||
}
|
||||
|
||||
@ -127,8 +129,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
super.onPageSelected(position);
|
||||
updateTitle(position);
|
||||
TabLayout.Tab tabAt = vb.tabLayout.getTabAt(position);
|
||||
if(tabAt!= null){
|
||||
if (tabAt != null) {
|
||||
tabAt.select();
|
||||
}
|
||||
}
|
||||
@ -136,6 +139,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
|
||||
private void updateTitle(int position) {
|
||||
if (position == 1) {
|
||||
vb.textviewSounds.setText(getString(R.string.favorites));
|
||||
}else {
|
||||
vb.textviewSounds.setText(getString(R.string.app_name));
|
||||
}
|
||||
}
|
||||
|
||||
private String getAppVersions() {
|
||||
String appversions = "";
|
||||
try {
|
||||
|
||||
@ -39,7 +39,7 @@ public class LoveFragment extends Fragment {
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
vb = FragmentLoveBinding.inflate(inflater,container,false);
|
||||
vb = FragmentLoveBinding.inflate(inflater, container, false);
|
||||
return vb.getRoot();
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ public class LoveFragment extends Fragment {
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
MySpace mySpace = new MySpace(20, 20, 25);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity());
|
||||
@ -61,6 +62,11 @@ public class LoveFragment extends Fragment {
|
||||
MyRoom.getInstance().getDataDao().queryLoveList(true).observe(requireActivity(), new Observer<List<MyData>>() {
|
||||
@Override
|
||||
public void onChanged(List<MyData> list) {
|
||||
if (list.size() > 0) {
|
||||
vb.tvNoFavorites.setVisibility(View.GONE);
|
||||
}else {
|
||||
vb.tvNoFavorites.setVisibility(View.VISIBLE);
|
||||
}
|
||||
loveAdapter.setMyDataList(list);
|
||||
}
|
||||
});
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.example.funnysounds.fragement;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.example.funnysounds.data.MyData;
|
||||
import com.example.funnysounds.databinding.FragmentLoveBinding;
|
||||
import com.example.funnysounds.databinding.FragmentRecordBinding;
|
||||
import com.example.funnysounds.resolve.MySpace;
|
||||
import com.example.funnysounds.room.MyRoom;
|
||||
import com.example.funnysounds.soundsadapter.LoveAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecordFragment extends Fragment {
|
||||
|
||||
private RankViewModel mViewModel;
|
||||
private FragmentRecordBinding vb;
|
||||
|
||||
public static RecordFragment newInstance() {
|
||||
return new RecordFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
vb = FragmentRecordBinding.inflate(inflater, container, false);
|
||||
return vb.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(RankViewModel.class);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
MySpace mySpace = new MySpace(20, 20, 25);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(requireActivity());
|
||||
vb.loveRecycler.setLayoutManager(layoutManager);
|
||||
vb.loveRecycler.addItemDecoration(mySpace);
|
||||
LoveAdapter loveAdapter = new LoveAdapter(requireActivity());
|
||||
|
||||
vb.loveRecycler.setAdapter(loveAdapter);
|
||||
MyRoom.getInstance().getDataDao().queryLoveList(true).observe(requireActivity(), new Observer<List<MyData>>() {
|
||||
@Override
|
||||
public void onChanged(List<MyData> list) {
|
||||
if (list.size() > 0) {
|
||||
vb.tvNoFavorites.setVisibility(View.GONE);
|
||||
}else {
|
||||
vb.tvNoFavorites.setVisibility(View.VISIBLE);
|
||||
}
|
||||
loveAdapter.setMyDataList(list);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package com.example.funnysounds.resolve;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
import com.example.funnysounds.action.IOListener;
|
||||
import com.example.funnysounds.data.CategoryList;
|
||||
import com.example.funnysounds.data.MyData;
|
||||
import com.example.funnysounds.room.MyRoom;
|
||||
@ -88,4 +89,15 @@ public class Readfile {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static Thread onSwitchIO(IOListener ioListener){
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ioListener.onRunIOAction();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,16 +6,21 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.funnysounds.R;
|
||||
import com.example.funnysounds.action.IOListener;
|
||||
import com.example.funnysounds.action.MyDataSounderListener;
|
||||
import com.example.funnysounds.activity.DetailActivity;
|
||||
import com.example.funnysounds.data.MyData;
|
||||
import com.example.funnysounds.databinding.ItemLoveBinding;
|
||||
import com.example.funnysounds.resolve.Readfile;
|
||||
import com.example.funnysounds.resolve.Sounds;
|
||||
import com.example.funnysounds.room.MyRoom;
|
||||
import com.example.funnysounds.value.StaticValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -72,6 +77,15 @@ public class LoveAdapter extends RecyclerView.Adapter<LoveAdapter.VH> {
|
||||
holder.getVb().imLove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
notifyItemRemoved(position);
|
||||
Toast.makeText(Sounds.mAppContext,myContext.getString(R.string.remove),Toast.LENGTH_SHORT).show();
|
||||
Readfile.onSwitchIO(new IOListener() {
|
||||
@Override
|
||||
public void onRunIOAction() {
|
||||
myData.setAddLove(false);
|
||||
MyRoom.getInstance().getDataDao().updatePrank(myData);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.MainActivity">
|
||||
tools:context=".activity.MainActivity"
|
||||
tools:openDrawer="right">
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
@ -76,91 +77,86 @@
|
||||
android:layout_gravity="right"
|
||||
android:background="@color/white">
|
||||
|
||||
<ImageView
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/right_logo"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="50dp"
|
||||
android:src="@mipmap/logo" />
|
||||
app:cardCornerRadius="12dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:src="@mipmap/logo" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/url_previcy"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:layout_below="@id/right_logo"
|
||||
android:layout_marginTop="50dp">
|
||||
android:layout_marginStart="22dp"
|
||||
android:layout_marginTop="27dp"
|
||||
android:layout_marginEnd="22dp"
|
||||
android:background="@drawable/menu_background"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/url_previcy"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:background="@drawable/menu_background"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/text_previcy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="@string/privacy"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_previcy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="@string/privacy"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="8dp"
|
||||
android:src="@mipmap/privacy" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/version_key"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/go_url" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/version_lay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:layout_below="@id/url_previcy"
|
||||
android:layout_marginTop="60dp"
|
||||
android:background="@drawable/menu_background"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="@string/app_version"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
</RelativeLayout>
|
||||
<ImageView
|
||||
android:id="@+id/version_key"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/go_url" />
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/version_lay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_below="@id/url_previcy"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="22dp"
|
||||
android:layout_marginEnd="22dp"
|
||||
android:background="@drawable/menu_background"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="20dp"
|
||||
android:text="@string/app_version"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:text="@string/app_name"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
@ -7,8 +7,15 @@
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/love_recycler"
|
||||
android:paddingTop="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="20dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_no_favorites"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/no_favorites" />
|
||||
|
||||
</FrameLayout>
|
||||
21
app/src/main/res/layout/fragment_record.xml
Normal file
21
app/src/main/res/layout/fragment_record.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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"
|
||||
tools:context=".fragement.LoveFragment">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/love_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="20dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_no_favorites"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/no_favorites" />
|
||||
|
||||
</FrameLayout>
|
||||
@ -1,8 +1,11 @@
|
||||
<resources>
|
||||
<string name="app_name">Funny Sounds</string>
|
||||
<string name="privacy">Privacy</string>
|
||||
<string name="privacy">privacy</string>
|
||||
<string name="url_privacy">https://sites.google.com/view/funnysoundsairhorn</string>
|
||||
<string name="app_version">Version</string>
|
||||
<string name="app_version">version</string>
|
||||
<string name="app_sounds_version">V%s</string>
|
||||
<string name="loop">Loop</string>
|
||||
<string name="remove">Removed from favorite</string>
|
||||
<string name="favorites">My Favorites</string>
|
||||
<string name="no_favorites">No favorites found</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user