zezung27 / api-mymeostore

1 stars 0 forks source link

EnableNotiActivity #6

Closed zezung27 closed 2 years ago

zezung27 commented 2 years ago

package com.matcos.dynamicislandlight.noti;

import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView;

import android.content.Context; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.ImageView; import android.widget.TextView;

import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.matcos.dynamicislandlight.R; import com.matcos.dynamicislandlight.utils.ApkExtractor; import com.matcos.dynamicislandlight.utils.Contanst; import com.matcos.dynamicislandlight.utils.Utils;

import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List;

public class EnableNotiActivity extends AppCompatActivity implements INotiEnableCheckbox{ private ArrayList mListPackageInit ; private ArrayList mListPackagePref ;

private RecyclerView mRecyclerView;
private PackageAdapter mPackageAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.hide();
    }
    getWindow().setStatusBarColor(getColor(R.color.white));
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    setContentView(R.layout.activity_enable_noti);

    mListPackageInit = new ArrayList<>();
    mListPackagePref = Utils.getArrayList(Contanst.NAME_PACKAGE, getBaseContext());
    getListAppInstalled();
    if(mListPackagePref != null && mListPackagePref.size() > 0) {
        for(int i = 0; i<mListPackagePref.size();i++) {
            if(mListPackageInit.get(i).getName().equals(mListPackagePref.get(i).getName())) {
                mListPackageInit.get(i).setCheck(mListPackagePref.get(i).isCheck());
            }
        }
    }
    mRecyclerView = findViewById(R.id.recyclerPackage);
    mPackageAdapter = new PackageAdapter(this, mListPackageInit);
    mPackageAdapter.setClickCheckBoxListener(this);
    mRecyclerView.setAdapter(mPackageAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    ImageView imgBack = findViewById(R.id.backIcon);
    TextView txtDone = findViewById(R.id.saveIntoPre);
    imgBack.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });

    txtDone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ArrayList<PackageModalPref> listPref = new ArrayList<>();
            ArrayList<PackageModal> list = mListPackageInit;
            for(PackageModal packModalData: list) {
                listPref.add(new PackageModalPref(packModalData.getName(), packModalData.getPackageName(), packModalData.isCheck()));
            }
            Utils.saveArrayList(listPref, Contanst.NAME_PACKAGE, getBaseContext());
            onBackPressed();
        }
    });
}

private void getListAppInstalled() {
    ApkExtractor apkExtractor = new ApkExtractor(this);
    List<String> apkPackageName = apkExtractor.GetAllInstalledApkInfo();
    for(String namePackage: apkPackageName){
        String appName = apkExtractor.GetAppName(namePackage);
        Drawable icon = apkExtractor.getAppIconByPackageName(namePackage);

        mListPackageInit.add(new PackageModal(appName, namePackage, icon, true));
    }
}

@Override
public void onClickCB(ArrayList<PackageModal> list) {
}

}