use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.
the class MainFragment method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
final BlockModel model = models.get(menuInfo.position);
switch(item.getItemId()) {
case 1:
models.remove(menuInfo.position);
adapter.notifyDataSetChanged();
saveAll();
break;
case 2:
new AlertDialog.Builder(context).setTitle(R.string.confirm).setMessage("是否要将此项设为不按类名定位?\n这样可能会解决一些无法屏蔽的问题,但是也会增加一些误伤的几率。\n\n注意:此操作不可逆!").setPositiveButton(R.string.OK, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
model.className = "*";
models.set(menuInfo.position, model);
adapter.notifyDataSetChanged();
saveAll();
}
}).setNegativeButton(R.string.cancel, null).show();
break;
case 3:
share(model.toString());
break;
case 4:
ArrayList<BlockModel> arrayList = new ArrayList<>();
for (Integer postion : deleteList) {
arrayList.add(models.get(postion));
}
models.removeAll(arrayList);
deleteList.clear();
adapter.notifyDataSetChanged();
saveAll();
break;
case 5:
ArrayList<BlockModel> shares = new ArrayList<>();
for (Integer postion : deleteList) {
shares.add(models.get(postion));
}
deleteList.clear();
StringBuilder stringBuilder = new StringBuilder();
for (BlockModel model1 : shares) {
stringBuilder.append(model1.toString());
stringBuilder.append("\n");
}
share(stringBuilder.toString());
adapter.notifyDataSetChanged();
break;
case 6:
model.enable = !model.enable;
models.set(menuInfo.position, model);
adapter.notifyDataSetChanged();
saveAll();
break;
default:
break;
}
return super.onContextItemSelected(item);
}
use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.
the class MainFragment method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
BlockModel model = models.get(info.position);
if (deleteList.size() > 0) {
menu.add(0, 4, Menu.NONE, R.string.delete_selections);
menu.add(0, 5, Menu.NONE, R.string.share_selections);
return;
}
menu.add(0, 1, Menu.NONE, R.string.delete_item);
menu.add(0, 3, Menu.NONE, R.string.share);
menu.add(0, 6, Menu.NONE, model.enable ? R.string.disable_item : R.string.enable_item);
}
use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.
the class MainFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
context = getActivity();
pm = context.getPackageManager();
FrameLayout layout = (FrameLayout) inflater.inflate(R.layout.main_fragment, null);
listView = (ListView) layout.findViewById(R.id.listView);
models = MainActivity.read();
try {
Collections.sort(models, new Comparator<BlockModel>() {
@Override
public int compare(BlockModel blockModel, BlockModel t1) {
String s1 = getAppTitle(pm, blockModel.packageName);
String s2 = getAppTitle(pm, t1.packageName);
// Synopsis: Updated sort behavior for Arrays and Collections may throw an IllegalArgumentException
if (s1.equals(s2)) {
return 0;
}
return Collator.getInstance(Locale.CHINA).compare(s1, s2);
}
});
} catch (IllegalArgumentException e) {
// So we will not sort them,OK?
e.printStackTrace();
}
adapter = new AppAdapter();
listView.setAdapter(adapter);
registerForContextMenu(listView);
final FloatingActionButton button = (FloatingActionButton) layout.findViewById(R.id.fab);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SelectAppWizard tw = new SelectAppWizard();
Bundle bundle = new Bundle();
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("system_app", false)) {
bundle.putBoolean("sys", true);
}
tw.setArguments(bundle);
if (context instanceof MainActivity) {
((MainActivity) context).setFragment(tw);
}
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
BlockModel model = models.get(i);
Bundle bundle = new Bundle();
bundle.putString("pkg", model.packageName);
bundle.putString("record", model.record);
bundle.putString("className", model.className);
InfoFragment infoFragment = new InfoFragment();
infoFragment.setArguments(bundle);
if (context instanceof MainActivity) {
((MainActivity) context).setFragment(infoFragment);
}
}
});
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
/* 标记是否滑动 */
boolean scrollFlag = false;
/* 标记第一次进入,因为第一次进来lastVisibleItemPosition默认为0, */
boolean isFirst = true;
/*
此时如果listview的第一个显示的条目不是第一个(下表为0),则往下滑也会出现firstVisibleItem>lastVisibleItemPosition的情况
所以第一次进入时不做操作,第二次进来已经给lastVisibleItemPosition赋值,就可以判断了
*/
/* 标记上次的显示位置 */
int lastVisibleItemPosition;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
scrollFlag = scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (!isFirst) {
if (firstVisibleItem < lastVisibleItemPosition) {
button.show();
// 执行向上滑动时要做的逻辑
} else if (firstVisibleItem > lastVisibleItemPosition) {
button.hide();
}
// 记录当前条目
lastVisibleItemPosition = firstVisibleItem;
}
isFirst = false;
}
});
return layout;
}
use of ml.qingsu.fuckview.models.BlockModel in project fuckView by w568w.
the class MainActivity method read.
public static ArrayList<BlockModel> read() {
ArrayList<BlockModel> list = new ArrayList<>();
ArrayList<String> lines = readPreferenceByLine(LIST_NAME);
for (String str : lines) {
BlockModel model = BlockModel.fromString(str);
if (model == null) {
continue;
}
if (model.record.contains(ALL_SPLIT)) {
model = ViewModel.fromString(str);
} else {
// 轉換老版(0.8.5-)規則到新版
model = ViewModel.fromString(ConvertUtils.oldToNew(model).toString());
}
if (model != null) {
list.add(model);
}
}
return list;
}
Aggregations