Archived
Initial Push
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder> {
|
||||
private List<Subst> mSubst;
|
||||
|
||||
public static class CardViewHolder extends RecyclerView.ViewHolder {
|
||||
public ImageView mImageView;
|
||||
public TextView mGroup, mDate, mTime, mCourse, mRoom, mAdditional;
|
||||
|
||||
public CardViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
mImageView = itemView.findViewById(R.id.iconView);
|
||||
mGroup = itemView.findViewById(R.id.group);
|
||||
mDate = itemView.findViewById(R.id.date);
|
||||
mTime = itemView.findViewById(R.id.time);
|
||||
mCourse = itemView.findViewById(R.id.course);
|
||||
mRoom = itemView.findViewById(R.id.room);
|
||||
mAdditional = itemView.findViewById(R.id.additional);
|
||||
}
|
||||
}
|
||||
|
||||
public CardAdapter(ArrayList<Subst> subst) {
|
||||
mSubst = subst;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CardViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.course_card, parent, false);
|
||||
CardViewHolder cvh = new CardViewHolder(v);
|
||||
return cvh;
|
||||
}
|
||||
|
||||
public Subst getSubstAt(int i) {
|
||||
return mSubst.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CardViewHolder holder, int position) {
|
||||
Subst currentItem = mSubst.get(position);
|
||||
|
||||
|
||||
holder.mImageView.setImageResource(currentItem.getIcon());
|
||||
holder.mGroup.setText(currentItem.getGroup());
|
||||
holder.mDate.setText(currentItem.getDate());
|
||||
holder.mTime.setText(currentItem.getTime());
|
||||
holder.mCourse.setText(currentItem.getCourse());
|
||||
holder.mRoom.setText(currentItem.getRoom());
|
||||
holder.mAdditional.setText(currentItem.getAdditional());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mSubst.size();
|
||||
}
|
||||
|
||||
public void setSubst(List<Subst> subst) {
|
||||
mSubst = subst;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
import com.jaredrummler.android.device.DeviceName;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class FirstTime extends AppCompatActivity {
|
||||
|
||||
private String manufacturer;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_first_time);
|
||||
setTheme(R.style.AppTheme0);
|
||||
|
||||
Window window = this.getWindow();
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
window.setStatusBarColor(ContextCompat.getColor(this, R.color.white));
|
||||
window.setNavigationBarColor(ContextCompat.getColor(this, R.color.white));
|
||||
} else {
|
||||
window.setStatusBarColor(ContextCompat.getColor(this, R.color.black));
|
||||
window.setNavigationBarColor(ContextCompat.getColor(this, R.color.black));
|
||||
}
|
||||
window.setBackgroundDrawable(getDrawable(R.drawable.white));
|
||||
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
|
||||
ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, ContextCompat.getColor(this, R.color.white));
|
||||
setTaskDescription(taskDesc);
|
||||
|
||||
final Context context = this;
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
final ExtendedFloatingActionButton fab = findViewById(R.id.efab);
|
||||
|
||||
final Intent start = new Intent(this, MainActivity.class);
|
||||
|
||||
final EditText name = findViewById(R.id.txtName);
|
||||
final EditText grade = findViewById(R.id.txtClasses);
|
||||
final EditText courses = findViewById(R.id.txtCourses);
|
||||
final CheckBox notif = findViewById(R.id.cbNotif);
|
||||
final CheckBox dark = findViewById(R.id.cbDark);
|
||||
final CheckBox pers = findViewById(R.id.cbPersonalised);
|
||||
final ImageButton helpClasses = findViewById(R.id.chipHelpClasses);
|
||||
final ImageButton helpCourses = findViewById(R.id.chipHelpCourses);
|
||||
|
||||
// TODO Huawei
|
||||
|
||||
// DeviceName.with(context).request(new DeviceName.Callback() {
|
||||
// @Override
|
||||
// public void onFinished(DeviceName.DeviceInfo info, Exception error) {
|
||||
// manufacturer = info.manufacturer;
|
||||
// if (manufacturer.contains("Huawei") ||
|
||||
// manufacturer.contains("Honor")) {
|
||||
//// if (true) {
|
||||
// notif.setEnabled(false);
|
||||
//
|
||||
// @ColorInt int color;
|
||||
//
|
||||
// TypedValue typedValue = new TypedValue();
|
||||
// Resources.Theme theme = context.getTheme();
|
||||
// theme.resolveAttribute(R.attr.colorHint, typedValue, true);
|
||||
// color = typedValue.data;
|
||||
//
|
||||
// notif.setTextColor(color);
|
||||
// edit.putBoolean("notif", false);
|
||||
// edit.putBoolean("autoRefresh", true);
|
||||
// edit.apply();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
helpCourses.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(context, R.style.AlertDialogCustomLight);
|
||||
alertDialog.setTitle(getString(R.string.helpCoursesTitle));
|
||||
View dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText(getString(R.string.helpCourses));
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
helpClasses.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(context, R.style.AlertDialogCustomLight);
|
||||
alertDialog.setTitle(getString(R.string.helpClassesTitle));
|
||||
View dialogView = LayoutInflater.from(context).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText(getString(R.string.helpClasses));
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
fab.setClickable(false);
|
||||
|
||||
edit.putString("firstTimeDev", String.valueOf(Calendar.getInstance().getTime()));
|
||||
edit.putString("username", name.getText().toString());
|
||||
edit.putString("classes", grade.getText().toString());
|
||||
edit.putString("courses", courses.getText().toString());
|
||||
if (dark.isChecked()) {
|
||||
edit.putInt("themeInt", 1);
|
||||
} else {
|
||||
edit.putInt("themeInt", 0);
|
||||
}
|
||||
if (notif.isChecked()) {
|
||||
edit.putBoolean("notif", true);
|
||||
} else {
|
||||
edit.putBoolean("notif", false);
|
||||
}
|
||||
if (pers.isChecked()) {
|
||||
edit.putBoolean("defaultPersonalised", true);
|
||||
} else {
|
||||
edit.putBoolean("defaultPersonalised", false);
|
||||
}
|
||||
|
||||
edit.putBoolean("firstTime", false);
|
||||
edit.apply();
|
||||
|
||||
final CoordinatorLayout cLayout = findViewById(R.id.coordinatorLayout);
|
||||
final LinearLayout linearInflation = findViewById(R.id.linearInflation);
|
||||
|
||||
int x = fab.getRight() - fab.getWidth() / 2;
|
||||
int y = fab.getBottom() - fab.getHeight() / 2;
|
||||
|
||||
int startRadius = 0;
|
||||
int endRadius = (int) Math.hypot(cLayout.getWidth(), cLayout.getHeight());
|
||||
|
||||
inflater.inflate(R.layout.welcome_screen, linearInflation, true);
|
||||
|
||||
Animator anim = ViewAnimationUtils.createCircularReveal(linearInflation, x, y, startRadius, endRadius);
|
||||
anim.setDuration(600);
|
||||
|
||||
final LinearLayout colour = findViewById(R.id.colourLayout);
|
||||
|
||||
linearInflation.setVisibility(View.VISIBLE);
|
||||
anim.start();
|
||||
|
||||
final Animation animationOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out_short);
|
||||
|
||||
final Handler handlerZero = new Handler();
|
||||
handlerZero.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
colour.startAnimation(animationOut);
|
||||
}
|
||||
}, 400);
|
||||
|
||||
animationOut.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
colour.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {}
|
||||
});
|
||||
|
||||
final Handler handlerOne = new Handler();
|
||||
handlerOne.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ImageView mImgCheck = findViewById(R.id.imageView);
|
||||
((Animatable) mImgCheck.getDrawable()).start();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startActivity(start);
|
||||
finish();
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
public class Food {
|
||||
|
||||
private String food;
|
||||
|
||||
public Food(String food) {
|
||||
this.food = food;
|
||||
}
|
||||
|
||||
public String getFood() {
|
||||
return food;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.CardViewHolder> {
|
||||
private List<Food> mFood;
|
||||
|
||||
public static class CardViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView mFood;
|
||||
|
||||
public CardViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
mFood = itemView.findViewById(R.id.cardInfoText);
|
||||
}
|
||||
}
|
||||
|
||||
public FoodAdapter(ArrayList<Food> food) {
|
||||
mFood = food;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CardViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.just_a_card, parent, false);
|
||||
CardViewHolder cvh = new CardViewHolder(v);
|
||||
return cvh;
|
||||
}
|
||||
|
||||
public Food getFoodAt(int i) {
|
||||
return mFood.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CardViewHolder holder, int position) {
|
||||
Food currentItem = mFood.get(position);
|
||||
|
||||
holder.mFood.setText(currentItem.getFood());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mFood.size();
|
||||
}
|
||||
|
||||
public void setFood(List<Food> food) {
|
||||
mFood = food;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
class FoodFragment {
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.madapps.prefrences.EasyPrefrences;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.LayoutAnimationController;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
|
||||
import static com.google.android.material.snackbar.Snackbar.make;
|
||||
|
||||
public class FragmentFood extends Fragment {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private FoodAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private ArrayList<Food> foodArrayList;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.food_layout, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final SwipeRefreshLayout pullToRefresh = getView().findViewById(R.id.pullToRefreshFood);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
final LayoutAnimationController animationIn = AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.layout_animation_fall_down);
|
||||
final LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
EasyPrefrences easyPrefs = new EasyPrefrences(getContext());
|
||||
ArrayList<String> foodListPopulation = new ArrayList<>(easyPrefs.getListString("foodListPrefs"));
|
||||
try {
|
||||
foodArrayList = new ArrayList<>();
|
||||
recyclerView = getView().findViewById(R.id.linear_food);
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new FoodAdapter(foodArrayList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
// try {
|
||||
// recyclerView.removeAllViews();
|
||||
// } catch (NullPointerException e) {
|
||||
//
|
||||
// }
|
||||
|
||||
for (int i = 0; i < foodListPopulation.size(); i++) {
|
||||
foodArrayList.add(new Food(foodListPopulation.get(i)));
|
||||
mAdapter.setFood(foodArrayList);
|
||||
recyclerView.scheduleLayoutAnimation();
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
}
|
||||
|
||||
pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class fetcher extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
boolean attempt = false, npe = false;
|
||||
Elements foodElements;
|
||||
Document docFood;
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
final SwipeRefreshLayout pullToRefresh = getView().findViewById(R.id.pullToRefreshFood);
|
||||
|
||||
protected fetcher() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
final ProgressBar progressBar = getView().getRootView().findViewById(R.id.progressBar);
|
||||
try {
|
||||
docFood = Jsoup.connect("https://djd4rkn355.github.io/food.html").get();
|
||||
foodElements = docFood.select("th");
|
||||
|
||||
attempt = true;
|
||||
|
||||
progressBar.setProgress(0);
|
||||
progressBar.setMax(foodElements.size());
|
||||
// progressBar.incrementProgressBy(paragraphs[0].size());
|
||||
} catch (IOException e1) {
|
||||
npe = true;
|
||||
} catch (NullPointerException e1) {
|
||||
npe = true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if (attempt) {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
final ProgressBar progressBar = getView().getRootView().findViewById(R.id.progressBar);
|
||||
EasyPrefrences easyPrefs = new EasyPrefrences(getContext());
|
||||
|
||||
ArrayList<String> foodList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
recyclerView.removeAllViews();
|
||||
foodArrayList.removeAll(foodArrayList);
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
|
||||
for (int foodInt = 0; foodInt < foodElements.size(); foodInt++) {
|
||||
|
||||
try {
|
||||
if (foodElements.get(foodInt).text().contains("Montag") ||
|
||||
foodElements.get(foodInt).text().contains("Dienstag") ||
|
||||
foodElements.get(foodInt).text().contains("Mittwoch") ||
|
||||
foodElements.get(foodInt).text().contains("Donnerstag") ||
|
||||
foodElements.get(foodInt).text().contains("Freitag")) {
|
||||
|
||||
if (foodElements.get(foodInt + 3).text().contains("Montag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Dienstag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Mittwoch") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Donnerstag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Freitag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("von")) {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text() + "\n" + foodElements.get(foodInt + 2).text());
|
||||
foodInt += 2;
|
||||
} else if (foodElements.get(foodInt + 2).text().contains("Montag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Dienstag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Mittwoch") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Donnerstag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Freitag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("von")) {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text());
|
||||
foodInt += 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
foodList.add(foodElements.get(foodInt).text());
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
try {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text() + "\n" + foodElements.get(foodInt + 2).text());
|
||||
break;
|
||||
} catch (IndexOutOfBoundsException e1) {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text());
|
||||
break;
|
||||
}
|
||||
}
|
||||
progressBar.incrementProgressBy(1);
|
||||
}
|
||||
|
||||
easyPrefs.putListString("foodListPrefs", foodList);
|
||||
|
||||
ArrayList<String> foodListPopulation = new ArrayList<>(easyPrefs.getListString("foodListPrefs"));
|
||||
|
||||
final LayoutAnimationController animationIn = AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.layout_animation_fall_down);
|
||||
final LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
for (int i = 0; i < foodListPopulation.size(); i++) {
|
||||
foodArrayList.add(new Food(foodListPopulation.get(i)));
|
||||
mAdapter.setFood(foodArrayList);
|
||||
recyclerView.scheduleLayoutAnimation();
|
||||
progressBar.incrementProgressBy(1);
|
||||
}
|
||||
|
||||
progressBar.setProgress(1000);
|
||||
|
||||
final Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressBar.startAnimation(fadeOut);
|
||||
}
|
||||
}, 200);
|
||||
|
||||
fadeOut.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation arg0) {
|
||||
progressBar.setProgress(0);
|
||||
}
|
||||
});
|
||||
try {
|
||||
pullToRefresh.setRefreshing(false);
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
|
||||
} catch (NullPointerException e) {
|
||||
// pullToRefresh.setRefreshing(false);
|
||||
}
|
||||
} else if (npe) {
|
||||
pullToRefresh.setRefreshing(false);
|
||||
View contextView = getView().getRootView().findViewById(R.id.coordination);
|
||||
Snackbar snackbar = make(contextView, getText(R.string.nointernet), Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null);
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
|
||||
import static com.google.android.material.snackbar.Snackbar.make;
|
||||
|
||||
public class FragmentPersonal extends Fragment {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private CardAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private ArrayList<Subst> planCardList;
|
||||
private TextView bottomSheetText;
|
||||
private SubstViewModel substViewModel;
|
||||
private boolean persPlanEmpty;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.plan, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final SwipeRefreshLayout pullToRefresh = getView().findViewById(R.id.pullToRefresh);
|
||||
bottomSheetText = getView().getRootView().findViewById(R.id.bottom_sheet_text);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
|
||||
planCardList = new ArrayList<>();
|
||||
recyclerView = getView().findViewById(R.id.linearRecycler);
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new CardAdapter(planCardList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
final TextView smileydown = getView().findViewById(R.id.smileydown);
|
||||
final TextView smileydowntext = getView().findViewById(R.id.smileydowntext);
|
||||
final LinearLayout linearsmiley = getView().findViewById(R.id.linearsmiley);
|
||||
|
||||
if (prefs.getInt("firstTimeOpening", 0) == 2) {
|
||||
if (!prefs.getBoolean("notif", false)) {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
edit.putInt("firstTimeOpening", 3);
|
||||
edit.apply();
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
}
|
||||
substViewModel = ViewModelProviders.of(getActivity()).get(SubstViewModel.class);
|
||||
substViewModel.getAllSubst().observe(this, new Observer<List<Subst>>() {
|
||||
@Override
|
||||
public void onChanged(List<Subst> substs) {
|
||||
try {
|
||||
if (planCardList != null) {
|
||||
planCardList.clear();
|
||||
}
|
||||
smileydown.setVisibility(View.GONE);
|
||||
smileydowntext.setVisibility(View.GONE);
|
||||
linearsmiley.setVisibility(View.GONE);
|
||||
persPlanEmpty = true;
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
for (int i = 0; i < substs.size(); i++) {
|
||||
|
||||
if (prefs.getString("courses", "").isEmpty() && !prefs.getString("classes", "").isEmpty()) {
|
||||
if (!substs.get(i).getGroup().isEmpty() && !substs.get(i).getGroup().equals("")) {
|
||||
if (prefs.getString("classes", "").contains(substs.get(i).getGroup()) || substs.get(i).getGroup().contains(prefs.getString("classes", ""))) {
|
||||
planCardList.add(substs.get(i));
|
||||
persPlanEmpty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for seniors
|
||||
else if (!prefs.getString("courses", "").isEmpty() && !prefs.getString("classes", "").isEmpty()) {
|
||||
if (!substs.get(i).getGroup().equals("") && !substs.get(i).getCourse().equals("")) {
|
||||
if (prefs.getString("courses", "").contains(substs.get(i).getCourse())) {
|
||||
if (prefs.getString("classes", "").contains(substs.get(i).getGroup()) || substs.get(i).getGroup().contains(prefs.getString("classes", ""))) {
|
||||
planCardList.add(substs.get(i));
|
||||
persPlanEmpty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
recyclerView.getAdapter().notifyDataSetChanged(); // TODO check whether this is necessary
|
||||
Collections.sort(planCardList, new Comparator<Subst>() {
|
||||
@Override
|
||||
public int compare(Subst lhs, Subst rhs) {
|
||||
return Integer.compare(rhs.getPriority(), lhs.getPriority());
|
||||
}
|
||||
});
|
||||
recyclerView.scheduleLayoutAnimation();
|
||||
mAdapter.setSubst(planCardList);
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (persPlanEmpty) {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
smileydown.setVisibility(View.VISIBLE);
|
||||
smileydowntext.setVisibility(View.VISIBLE);
|
||||
linearsmiley.setVisibility(View.VISIBLE);
|
||||
linearsmiley.scheduleLayoutAnimation();
|
||||
}
|
||||
}
|
||||
}, 64);
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// pullToRefresh.setRefreshing(true);
|
||||
// new fetcher().execute();
|
||||
|
||||
pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class fetcher extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private int count = 0, pCount = 0, priority = 200;
|
||||
final String OLD_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz", NEW_FORMAT = "yyyy-MM-dd, HH:mm:ss";
|
||||
String newDateString, informational;
|
||||
String[] groupS, dateS, timeS, courseS, roomS, additionalS;
|
||||
boolean attempt = false, npe = false, emptyIcon;
|
||||
URL url;
|
||||
URLConnection connection;
|
||||
String modified;
|
||||
Elements rows, paragraphs;
|
||||
Document doc;
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
final SwipeRefreshLayout pullToRefresh = getView().findViewById(R.id.pullToRefresh);
|
||||
ProgressBar progressBar;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
|
||||
Date d;
|
||||
|
||||
protected fetcher() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
try {
|
||||
doc = Jsoup.connect("https://djd4rkn355.github.io/subst").get();
|
||||
url = new URL("https://djd4rkn355.github.io/subst");
|
||||
connection = url.openConnection();
|
||||
rows = doc.select("tr");
|
||||
count = rows.size();
|
||||
modified = connection.getHeaderField("Last-Modified");
|
||||
d = new Date(connection.getHeaderField("Last-Modified"));
|
||||
edit.putString("time", connection.getHeaderField("Last-Modified"));
|
||||
paragraphs = doc.select("p");
|
||||
pCount = paragraphs.size();
|
||||
attempt = true;
|
||||
|
||||
for (int i = 0; i < pCount; i++) {
|
||||
if (i == 0) {
|
||||
informational = paragraphs.get(i).text();
|
||||
} else {
|
||||
informational += "\n\n" + paragraphs.get(i).text();
|
||||
}
|
||||
}
|
||||
edit.putString("informational", informational);
|
||||
edit.apply();
|
||||
|
||||
groupS = new String[count];
|
||||
dateS = new String[count];
|
||||
timeS = new String[count];
|
||||
courseS = new String[count];
|
||||
roomS = new String[count];
|
||||
additionalS = new String[count];
|
||||
|
||||
progressBar = getView().getRootView().findViewById(R.id.progressBar);
|
||||
progressBar.setProgress(0);
|
||||
progressBar.setMax(count);
|
||||
|
||||
substViewModel.deleteAllSubst();
|
||||
|
||||
if (attempt) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
Element row = rows.get(i);
|
||||
Elements cols = row.select("th");
|
||||
groupS[i] = cols.get(0).text();
|
||||
dateS[i] = cols.get(1).text();
|
||||
timeS[i] = cols.get(2).text();
|
||||
courseS[i] = cols.get(3).text();
|
||||
roomS[i] = cols.get(4).text();
|
||||
additionalS[i] = cols.get(5).text();
|
||||
progressBar.incrementProgressBy(1);
|
||||
|
||||
int drawable = icons(courseS[i]);
|
||||
Subst subst = new Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i], roomS[i], additionalS[i], priority);
|
||||
substViewModel.insert(subst);
|
||||
priority--;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e1) {
|
||||
npe = true;
|
||||
} catch (NullPointerException e1) {
|
||||
npe = true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int icons(String course) {
|
||||
emptyIcon = false;
|
||||
if (course.toLowerCase().contains("deu") || course.toLowerCase().contains("dep") || course.toLowerCase().contains("daz")) {
|
||||
return R.drawable.ic_german;
|
||||
} else if (course.toLowerCase().contains("mat") || course.toLowerCase().contains("map")) {
|
||||
return R.drawable.ic_maths;
|
||||
} else if (course.toLowerCase().contains("eng") || course.toLowerCase().contains("enp") || course.toLowerCase().contains("ena")) {
|
||||
return R.drawable.ic_english;
|
||||
} else if (course.toLowerCase().contains("spo") || course.toLowerCase().contains("spp") || course.toLowerCase().contains("spth")) {
|
||||
return R.drawable.ic_pe;
|
||||
} else if (course.toLowerCase().contains("pol") || course.toLowerCase().contains("pop")) {
|
||||
return R.drawable.ic_politics;
|
||||
} else if (course.toLowerCase().contains("dar") || course.toLowerCase().contains("dap")) {
|
||||
return R.drawable.ic_drama;
|
||||
} else if (course.toLowerCase().contains("phy") || course.toLowerCase().contains("php")) {
|
||||
return R.drawable.ic_physics;
|
||||
} else if (course.toLowerCase().contains("bio") || course.toLowerCase().contains("bip") || course.toLowerCase().contains("nw")) {
|
||||
return R.drawable.ic_biology;
|
||||
} else if (course.toLowerCase().contains("che") || course.toLowerCase().contains("chp")) {
|
||||
return R.drawable.ic_chemistry;
|
||||
} else if (course.toLowerCase().contains("phi") || course.toLowerCase().contains("psp")) {
|
||||
return R.drawable.ic_philosophy;
|
||||
} else if (course.toLowerCase().contains("laa") || course.toLowerCase().contains("laf") || course.toLowerCase().contains("lat")) {
|
||||
return R.drawable.ic_latin;
|
||||
} else if (course.toLowerCase().contains("spa") || course.toLowerCase().contains("spf")) {
|
||||
return R.drawable.ic_spanish;
|
||||
} else if (course.toLowerCase().contains("fra") || course.toLowerCase().contains("frf") || course.toLowerCase().contains("frz")) {
|
||||
return R.drawable.ic_french;
|
||||
} else if (course.toLowerCase().contains("inf")) {
|
||||
return R.drawable.ic_compsci;
|
||||
} else if (course.toLowerCase().contains("ges")) {
|
||||
return R.drawable.ic_history;
|
||||
} else if (course.toLowerCase().contains("rel")) {
|
||||
return R.drawable.ic_religion;
|
||||
} else if (course.toLowerCase().contains("geg") || course.toLowerCase().contains("wuk")) {
|
||||
return R.drawable.ic_geography;
|
||||
} else if (course.toLowerCase().contains("kun")) {
|
||||
return R.drawable.ic_arts;
|
||||
} else if (course.toLowerCase().contains("mus")) {
|
||||
return R.drawable.ic_music;
|
||||
} else if (course.toLowerCase().contains("tue")) {
|
||||
return R.drawable.ic_turkish;
|
||||
} else if (course.toLowerCase().contains("chi")) {
|
||||
return R.drawable.ic_chinese;
|
||||
} else if (course.toLowerCase().contains("gll")) {
|
||||
return R.drawable.ic_gll;
|
||||
} else if (course.toLowerCase().contains("wat")) {
|
||||
return R.drawable.ic_wat;
|
||||
} else if (course.toLowerCase().contains("för")) {
|
||||
return R.drawable.ic_help;
|
||||
} else if (course.toLowerCase().contains("wp") || course.toLowerCase().contains("met")) {
|
||||
return R.drawable.ic_pencil;
|
||||
} else {
|
||||
emptyIcon = true;
|
||||
return R.drawable.ic_empty;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
try {
|
||||
if (attempt) {
|
||||
final Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressBar.startAnimation(fadeOut);
|
||||
}
|
||||
}, 200);
|
||||
|
||||
fadeOut.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation arg0) {
|
||||
progressBar.setProgress(0);
|
||||
}
|
||||
});
|
||||
|
||||
sdf.applyPattern(NEW_FORMAT);
|
||||
newDateString = sdf.format(d);
|
||||
View contextView = getView().getRootView().findViewById(R.id.coordination);
|
||||
Snackbar snackbar = make(contextView, getText(R.string.lastupdated) + ": " + newDateString, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null);
|
||||
snackbar.show();
|
||||
|
||||
pullToRefresh.setRefreshing(false);
|
||||
} else if (npe) {
|
||||
pullToRefresh.setRefreshing(false);
|
||||
View contextView = getView().getRootView().findViewById(R.id.coordination);
|
||||
Snackbar snackbar = make(contextView, getText(R.string.nointernet), Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null);
|
||||
snackbar.show();
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.android.material.snackbar.Snackbar.make;
|
||||
|
||||
public class FragmentPlan extends Fragment {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private CardAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private ArrayList<Subst> planCardList;
|
||||
private TextView bottomSheetText;
|
||||
private SubstViewModel substViewModel;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.plan, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final SwipeRefreshLayout pullToRefresh = getView().findViewById(R.id.pullToRefresh);
|
||||
bottomSheetText = getView().getRootView().findViewById(R.id.bottom_sheet_text);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
|
||||
planCardList = new ArrayList<>();
|
||||
recyclerView = getView().findViewById(R.id.linearRecycler);
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new CardAdapter(planCardList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
if (prefs.getInt("firstTimeOpening", 0) == 2) {
|
||||
if (!prefs.getBoolean("notif", false)) {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
edit.putInt("firstTimeOpening", 3);
|
||||
edit.apply();
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
}
|
||||
substViewModel = ViewModelProviders.of(getActivity()).get(SubstViewModel.class);
|
||||
substViewModel.getAllSubst().observe(this, new Observer<List<Subst>>() {
|
||||
@Override
|
||||
public void onChanged(List<Subst> substs) {
|
||||
// LayoutAnimationController animationOut = AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_animation_fall_down_out);
|
||||
// LayoutAnimationController animationIn = AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_animation_fall_down);
|
||||
// recyclerView.setLayoutAnimation(animationOut);
|
||||
// recyclerView.scheduleLayoutAnimation();
|
||||
mAdapter.setSubst(substs);
|
||||
// recyclerView.setLayoutAnimation(animationIn);
|
||||
recyclerView.scheduleLayoutAnimation();
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
pullToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
pullToRefresh.setRefreshing(true);
|
||||
new fetcher().execute();
|
||||
bottomSheetText.setText(prefs.getString("informational", getString(R.string.noinfo)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class fetcher extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private int count = 0, pCount = 0, priority = 200;
|
||||
final String OLD_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz", NEW_FORMAT = "yyyy-MM-dd, HH:mm:ss";
|
||||
String newDateString, informational;
|
||||
String[] groupS, dateS, timeS, courseS, roomS, additionalS;
|
||||
boolean attempt = false, npe = false, emptyIcon;
|
||||
URL url;
|
||||
URLConnection connection;
|
||||
String modified;
|
||||
Elements rows, paragraphs;
|
||||
Document doc;
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
final SwipeRefreshLayout pullToRefresh = getView().findViewById(R.id.pullToRefresh);
|
||||
ProgressBar progressBar;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
|
||||
Date d;
|
||||
|
||||
protected fetcher() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
try {
|
||||
doc = Jsoup.connect("https://djd4rkn355.github.io/subst").get();
|
||||
url = new URL("https://djd4rkn355.github.io/subst");
|
||||
connection = url.openConnection();
|
||||
rows = doc.select("tr");
|
||||
count = rows.size();
|
||||
modified = connection.getHeaderField("Last-Modified");
|
||||
d = new Date(connection.getHeaderField("Last-Modified"));
|
||||
edit.putString("time", connection.getHeaderField("Last-Modified"));
|
||||
paragraphs = doc.select("p");
|
||||
pCount = paragraphs.size();
|
||||
attempt = true;
|
||||
|
||||
for (int i = 0; i < pCount; i++) {
|
||||
if (i == 0) {
|
||||
informational = paragraphs.get(i).text();
|
||||
} else {
|
||||
informational += "\n\n" + paragraphs.get(i).text();
|
||||
}
|
||||
}
|
||||
edit.putString("informational", informational);
|
||||
edit.apply();
|
||||
|
||||
groupS = new String[count];
|
||||
dateS = new String[count];
|
||||
timeS = new String[count];
|
||||
courseS = new String[count];
|
||||
roomS = new String[count];
|
||||
additionalS = new String[count];
|
||||
|
||||
progressBar = getView().getRootView().findViewById(R.id.progressBar);
|
||||
progressBar.setProgress(0);
|
||||
progressBar.setMax(count);
|
||||
|
||||
substViewModel.deleteAllSubst();
|
||||
|
||||
if (attempt) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
Element row = rows.get(i);
|
||||
Elements cols = row.select("th");
|
||||
groupS[i] = cols.get(0).text();
|
||||
dateS[i] = cols.get(1).text();
|
||||
timeS[i] = cols.get(2).text();
|
||||
courseS[i] = cols.get(3).text();
|
||||
roomS[i] = cols.get(4).text();
|
||||
additionalS[i] = cols.get(5).text();
|
||||
progressBar.incrementProgressBy(1);
|
||||
|
||||
int drawable = icons(courseS[i]);
|
||||
Subst subst = new Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i], roomS[i], additionalS[i], priority);
|
||||
substViewModel.insert(subst);
|
||||
priority--;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e1) {
|
||||
npe = true;
|
||||
} catch (NullPointerException e1) {
|
||||
npe = true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int icons(String course) {
|
||||
emptyIcon = false;
|
||||
if (course.toLowerCase().contains("deu") || course.toLowerCase().contains("dep") || course.toLowerCase().contains("daz")) {
|
||||
return R.drawable.ic_german;
|
||||
} else if (course.toLowerCase().contains("mat") || course.toLowerCase().contains("map")) {
|
||||
return R.drawable.ic_maths;
|
||||
} else if (course.toLowerCase().contains("eng") || course.toLowerCase().contains("enp") || course.toLowerCase().contains("ena")) {
|
||||
return R.drawable.ic_english;
|
||||
} else if (course.toLowerCase().contains("spo") || course.toLowerCase().contains("spp") || course.toLowerCase().contains("spth")) {
|
||||
return R.drawable.ic_pe;
|
||||
} else if (course.toLowerCase().contains("pol") || course.toLowerCase().contains("pop")) {
|
||||
return R.drawable.ic_politics;
|
||||
} else if (course.toLowerCase().contains("dar") || course.toLowerCase().contains("dap")) {
|
||||
return R.drawable.ic_drama;
|
||||
} else if (course.toLowerCase().contains("phy") || course.toLowerCase().contains("php")) {
|
||||
return R.drawable.ic_physics;
|
||||
} else if (course.toLowerCase().contains("bio") || course.toLowerCase().contains("bip") || course.toLowerCase().contains("nw")) {
|
||||
return R.drawable.ic_biology;
|
||||
} else if (course.toLowerCase().contains("che") || course.toLowerCase().contains("chp")) {
|
||||
return R.drawable.ic_chemistry;
|
||||
} else if (course.toLowerCase().contains("phi") || course.toLowerCase().contains("psp")) {
|
||||
return R.drawable.ic_philosophy;
|
||||
} else if (course.toLowerCase().contains("laa") || course.toLowerCase().contains("laf") || course.toLowerCase().contains("lat")) {
|
||||
return R.drawable.ic_latin;
|
||||
} else if (course.toLowerCase().contains("spa") || course.toLowerCase().contains("spf")) {
|
||||
return R.drawable.ic_spanish;
|
||||
} else if (course.toLowerCase().contains("fra") || course.toLowerCase().contains("frf") || course.toLowerCase().contains("frz")) {
|
||||
return R.drawable.ic_french;
|
||||
} else if (course.toLowerCase().contains("inf")) {
|
||||
return R.drawable.ic_compsci;
|
||||
} else if (course.toLowerCase().contains("ges")) {
|
||||
return R.drawable.ic_history;
|
||||
} else if (course.toLowerCase().contains("rel")) {
|
||||
return R.drawable.ic_religion;
|
||||
} else if (course.toLowerCase().contains("geg") || course.toLowerCase().contains("wuk")) {
|
||||
return R.drawable.ic_geography;
|
||||
} else if (course.toLowerCase().contains("kun")) {
|
||||
return R.drawable.ic_arts;
|
||||
} else if (course.toLowerCase().contains("mus")) {
|
||||
return R.drawable.ic_music;
|
||||
} else if (course.toLowerCase().contains("tue")) {
|
||||
return R.drawable.ic_turkish;
|
||||
} else if (course.toLowerCase().contains("chi")) {
|
||||
return R.drawable.ic_chinese;
|
||||
} else if (course.toLowerCase().contains("gll")) {
|
||||
return R.drawable.ic_gll;
|
||||
} else if (course.toLowerCase().contains("wat")) {
|
||||
return R.drawable.ic_wat;
|
||||
} else if (course.toLowerCase().contains("för")) {
|
||||
return R.drawable.ic_help;
|
||||
} else if (course.toLowerCase().contains("wp") || course.toLowerCase().contains("met")) {
|
||||
return R.drawable.ic_pencil;
|
||||
} else {
|
||||
emptyIcon = true;
|
||||
return R.drawable.ic_empty;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
try {
|
||||
if (attempt) {
|
||||
final Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.fade_out);
|
||||
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressBar.startAnimation(fadeOut);
|
||||
}
|
||||
}, 200);
|
||||
|
||||
fadeOut.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation arg0) {
|
||||
progressBar.setProgress(0);
|
||||
}
|
||||
});
|
||||
|
||||
sdf.applyPattern(NEW_FORMAT);
|
||||
newDateString = sdf.format(d);
|
||||
View contextView = getView().getRootView().findViewById(R.id.coordination);
|
||||
Snackbar snackbar = make(contextView, getText(R.string.lastupdated) + ": " + newDateString, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null);
|
||||
snackbar.show();
|
||||
|
||||
pullToRefresh.setRefreshing(false);
|
||||
} else if (npe) {
|
||||
pullToRefresh.setRefreshing(false);
|
||||
View contextView = getView().getRootView().findViewById(R.id.coordination);
|
||||
Snackbar snackbar = make(contextView, getText(R.string.nointernet), Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null);
|
||||
snackbar.show();
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.android.material.snackbar.Snackbar.make;
|
||||
|
||||
public class FragmentSearch extends Fragment {
|
||||
|
||||
ConstraintLayout constraintLayout;
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private CardAdapter mAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
private ArrayList<Subst> planCardList;
|
||||
private SubstViewModel substViewModel;
|
||||
private boolean search = false;
|
||||
private EditText searchfield;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.search, container, false);
|
||||
constraintLayout = rootView.findViewById(R.id.fragment_container);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final ProgressBar progressBar = getView().getRootView().findViewById(R.id.progressBar);
|
||||
progressBar.setProgress(0);
|
||||
|
||||
planCardList = new ArrayList<>();
|
||||
recyclerView = getView().findViewById(R.id.linearRecyclerSearch);
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new CardAdapter(planCardList);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
searchfield = getView().findViewById(R.id.searchbar);
|
||||
searchfield.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
substViewModel = ViewModelProviders.of(getActivity()).get(SubstViewModel.class);
|
||||
substViewModel.getAllSubst().observe(getActivity(), new Observer<List<Subst>>() {
|
||||
@Override
|
||||
public void onChanged(List<Subst> substs) {
|
||||
planCardList.removeAll(substs);
|
||||
new search(substs).searchSth();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private class search extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private List<Subst> substs;
|
||||
|
||||
protected search(List<Subst> substs) {
|
||||
this.substs = substs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void searchSth() {
|
||||
for (int i = 0; i < substs.size(); i++) {
|
||||
if (substs.get(i).getGroup().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
search = true;
|
||||
}
|
||||
if (substs.get(i).getDate().toLowerCase().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
search = true;
|
||||
}
|
||||
if (substs.get(i).getTime().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
search = true;
|
||||
}
|
||||
if (substs.get(i).getCourse().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
search = true;
|
||||
}
|
||||
if (substs.get(i).getRoom().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
search = true;
|
||||
}
|
||||
if (substs.get(i).getAdditional().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
search = true;
|
||||
}
|
||||
|
||||
if (search) {
|
||||
planCardList.add(substs.get(i));
|
||||
search = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private class fetcher extends AsyncTask<Void, Void, Void> {
|
||||
//
|
||||
// private int count = 0, iconColour;
|
||||
// String[] groupS, dateS, timeS, courseS, roomS, additionalS;
|
||||
// boolean attempt = false, search = false, first = false, npe = false, emptyIcon;
|
||||
// Elements rows;
|
||||
// Document doc;
|
||||
// final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
// private RecyclerView recyclerView;
|
||||
// private CardAdapter mAdapter;
|
||||
// private RecyclerView.LayoutManager layoutManager;
|
||||
// private ArrayList<Subst> planCardList;
|
||||
//
|
||||
// protected fetcher() {}
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground(Void... params) {
|
||||
//
|
||||
// if (!first) {
|
||||
// try {
|
||||
// doc = Jsoup.connect("https://djd4rkn355.github.io/subst").get();
|
||||
// rows = doc.select("tr");
|
||||
// count = rows.size();
|
||||
// attempt = true;
|
||||
//
|
||||
// } catch (IOException e1) {
|
||||
// npe = true;
|
||||
// }
|
||||
//
|
||||
// groupS = new String[count];
|
||||
// dateS = new String[count];
|
||||
// timeS = new String[count];
|
||||
// courseS = new String[count];
|
||||
// roomS = new String[count];
|
||||
// additionalS = new String[count];
|
||||
//
|
||||
// if (attempt) {
|
||||
// for (int i = 0; i < count; i++) {
|
||||
// Element row = rows.get(i);
|
||||
// Elements cols = row.select("th");
|
||||
// groupS[i] = cols.get(0).text();
|
||||
// dateS[i] = cols.get(1).text();
|
||||
// timeS[i] = cols.get(2).text();
|
||||
// courseS[i] = cols.get(3).text();
|
||||
// roomS[i] = cols.get(4).text();
|
||||
// additionalS[i] = cols.get(5).text();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (prefs.getInt("themeInt", 0) == 0) {
|
||||
// iconColour = Color.parseColor("#212121");
|
||||
// }
|
||||
// if (prefs.getInt("themeInt", 0) == 1) {
|
||||
// iconColour = Color.parseColor("#e0e0e0");
|
||||
// }
|
||||
// first = true;
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private int icons(String[] courseS, int i) {
|
||||
// emptyIcon = false;
|
||||
// if (courseS[i].toLowerCase().contains("deu") || courseS[i].toLowerCase().contains("dep") || courseS[i].toLowerCase().contains("daz")) {
|
||||
// return R.drawable.ic_german;
|
||||
// } else if (courseS[i].toLowerCase().contains("mat") || courseS[i].toLowerCase().contains("map")) {
|
||||
// return R.drawable.ic_maths;
|
||||
// } else if (courseS[i].toLowerCase().contains("eng") || courseS[i].toLowerCase().contains("enp") || courseS[i].toLowerCase().contains("ena")) {
|
||||
// return R.drawable.ic_english;
|
||||
// } else if (courseS[i].toLowerCase().contains("spo") || courseS[i].toLowerCase().contains("spp") || courseS[i].toLowerCase().contains("spth")) {
|
||||
// return R.drawable.ic_pe;
|
||||
// } else if (courseS[i].toLowerCase().contains("pol") || courseS[i].toLowerCase().contains("pop")) {
|
||||
// return R.drawable.ic_politics;
|
||||
// } else if (courseS[i].toLowerCase().contains("dar") || courseS[i].toLowerCase().contains("dap")) {
|
||||
// return R.drawable.ic_drama;
|
||||
// } else if (courseS[i].toLowerCase().contains("phy") || courseS[i].toLowerCase().contains("php")) {
|
||||
// return R.drawable.ic_physics;
|
||||
// } else if (courseS[i].toLowerCase().contains("bio") || courseS[i].toLowerCase().contains("bip") || courseS[i].toLowerCase().contains("nw")) {
|
||||
// return R.drawable.ic_biology;
|
||||
// } else if (courseS[i].toLowerCase().contains("che") || courseS[i].toLowerCase().contains("chp")) {
|
||||
// return R.drawable.ic_chemistry;
|
||||
// } else if (courseS[i].toLowerCase().contains("phi") || courseS[i].toLowerCase().contains("psp")) {
|
||||
// return R.drawable.ic_philosophy;
|
||||
// } else if (courseS[i].toLowerCase().contains("laa") || courseS[i].toLowerCase().contains("laf") || courseS[i].toLowerCase().contains("lat")) {
|
||||
// return R.drawable.ic_latin;
|
||||
// } else if (courseS[i].toLowerCase().contains("spa") || courseS[i].toLowerCase().contains("spf")) {
|
||||
// return R.drawable.ic_spanish;
|
||||
// } else if (courseS[i].toLowerCase().contains("fra") || courseS[i].toLowerCase().contains("frf") || courseS[i].toLowerCase().contains("frz")) {
|
||||
// return R.drawable.ic_french;
|
||||
// } else if (courseS[i].toLowerCase().contains("inf")) {
|
||||
// return R.drawable.ic_compsci;
|
||||
// } else if (courseS[i].toLowerCase().contains("ges")) {
|
||||
// return R.drawable.ic_history;
|
||||
// } else if (courseS[i].toLowerCase().contains("rel")) {
|
||||
// return R.drawable.ic_religion;
|
||||
// } else if (courseS[i].toLowerCase().contains("geg") || courseS[i].toLowerCase().contains("wuk")) {
|
||||
// return R.drawable.ic_geography;
|
||||
// } else if (courseS[i].toLowerCase().contains("kun")) {
|
||||
// return R.drawable.ic_arts;
|
||||
// } else if (courseS[i].toLowerCase().contains("mus")) {
|
||||
// return R.drawable.ic_music;
|
||||
// } else if (courseS[i].toLowerCase().contains("tue")) {
|
||||
// return R.drawable.ic_turkish;
|
||||
// } else if (courseS[i].toLowerCase().contains("chi")) {
|
||||
// return R.drawable.ic_chinese;
|
||||
// } else if (courseS[i].toLowerCase().contains("gll")) {
|
||||
// return R.drawable.ic_gll;
|
||||
// } else if (courseS[i].toLowerCase().contains("wat")) {
|
||||
// return R.drawable.ic_wat;
|
||||
// } else if (courseS[i].toLowerCase().contains("för")) {
|
||||
// return R.drawable.ic_help;
|
||||
// } else if (courseS[i].toLowerCase().contains("wp") || courseS[i].toLowerCase().contains("met")) {
|
||||
// return R.drawable.ic_pencil;
|
||||
// } else {
|
||||
// emptyIcon = true;
|
||||
// return R.drawable.ic_empty;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Void result) {
|
||||
// if (attempt) {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// planCardList = new ArrayList<>();
|
||||
// recyclerView = getView().findViewById(R.id.linearRecyclerSearch);
|
||||
// layoutManager = new LinearLayoutManager(getContext());
|
||||
// recyclerView.setHasFixedSize(true);
|
||||
// recyclerView.setLayoutManager(layoutManager);
|
||||
// mAdapter = new CardAdapter(planCardList);
|
||||
// recyclerView.setAdapter(mAdapter);
|
||||
// } catch (NullPointerException e) {
|
||||
// return;
|
||||
// }
|
||||
// recyclerView.removeAllViews();
|
||||
// EditText searchfield = getView().findViewById(R.id.searchbar);
|
||||
// final Animation animationIn = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in);
|
||||
//
|
||||
// for (int i = 0; i < count; i++) {
|
||||
// if (groupS[i].toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
// search = true;
|
||||
// } if (dateS[i].toLowerCase().toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
// search = true;
|
||||
// } if (timeS[i].toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
// search = true;
|
||||
// } if (courseS[i].toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
// search = true;
|
||||
// } if (roomS[i].toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
// search = true;
|
||||
// } if (additionalS[i].toLowerCase().contains(searchfield.getText().toString().toLowerCase())) {
|
||||
// search = true;
|
||||
// }
|
||||
//
|
||||
// if (search) {
|
||||
// Drawable drawable = getResources().getDrawable(icons(courseS, i));
|
||||
// if (!emptyIcon) {
|
||||
// drawable.setTint(iconColour);
|
||||
// }
|
||||
// planCardList.add(new Subst(0, groupS[i], dateS[i], timeS[i], courseS[i], roomS[i], additionalS[i], 0));
|
||||
// recyclerView.setAnimation(animationIn);
|
||||
// search = false;
|
||||
// }
|
||||
// }
|
||||
// } else if (npe) {
|
||||
// View contextView = getView().getRootView().findViewById(R.id.coordination);
|
||||
// Snackbar snackbar = make(contextView, getText(R.string.nointernet), Snackbar.LENGTH_LONG)
|
||||
// .setAction("Action", null);
|
||||
// snackbar.show();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,646 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jaredrummler.android.device.DeviceName;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Random;
|
||||
|
||||
public class FragmentSettings extends Fragment {
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
private int cs = 7;
|
||||
private String manufacturer, name, model;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.content_settings, container, false);
|
||||
coordinatorLayout = rootView.findViewById(R.id.fragment_container);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final ProgressBar progressBar = getView().getRootView().findViewById(R.id.progressBar);
|
||||
progressBar.setProgress(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
builder.setToolbarColor(getResources().getColor(R.color.white));
|
||||
final CustomTabsIntent customTabsIntent = builder.build();
|
||||
|
||||
final EditText txtName = getView().findViewById(R.id.txtName);
|
||||
final Switch greeting = getView().findViewById(R.id.switchDisableGreeting);
|
||||
final Switch darkmode = getView().findViewById(R.id.switchDark);
|
||||
|
||||
final EditText txtClasses = getView().findViewById(R.id.txtClasses);
|
||||
final EditText txtCourses = getView().findViewById(R.id.txtCourses);
|
||||
final ImageButton helpClasses = getView().findViewById(R.id.chipHelpClasses);
|
||||
final ImageButton helpCourses = getView().findViewById(R.id.chipHelpCourses);
|
||||
|
||||
final Switch notifswitch = getView().findViewById(R.id.switchNotifications);
|
||||
|
||||
final Switch defaultPlan = getView().findViewById(R.id.switchDefaultPlan);
|
||||
final Switch openInfo = getView().findViewById(R.id.switchOpenInfo);
|
||||
final Switch autoRefresh = getView().findViewById(R.id.switchAutoRefresh);
|
||||
final LinearLayout website = getView().findViewById(R.id.btnWebsite);
|
||||
final LinearLayout licences = getView().findViewById(R.id.btnLicences);
|
||||
final TextView versionNumber = getView().findViewById(R.id.txtVersionTwo);
|
||||
|
||||
final LinearLayout tac = getView().findViewById(R.id.btnTerms);
|
||||
final LinearLayout privacy = getView().findViewById(R.id.btnPrivacyP);
|
||||
final LinearLayout version = getView().findViewById(R.id.btnVersion);
|
||||
|
||||
final TextView notif1 = getView().findViewById(R.id.txtNotifications);
|
||||
final TextView auto1 = getView().findViewById(R.id.txtAutoRefresh);
|
||||
final TextView notif2 = getView().findViewById(R.id.txtNotifiedAbout);
|
||||
final TextView auto2 = getView().findViewById(R.id.txtAutoRefreshTwo);
|
||||
|
||||
helpCourses.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle(getString(R.string.helpCoursesTitle));
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText(getString(R.string.helpCourses));
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
helpClasses.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle(getString(R.string.helpClassesTitle));
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText(getString(R.string.helpClasses));
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
txtName.setText(prefs.getString("username", ""));
|
||||
txtName.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
edit.putString("username", txtName.getText().toString());
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
if (!prefs.getBoolean("greeting", false)) {
|
||||
greeting.setChecked(false);
|
||||
}
|
||||
if (prefs.getBoolean("greeting", false)) {
|
||||
greeting.setChecked(true);
|
||||
}
|
||||
|
||||
greeting.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.putBoolean("greeting", true);
|
||||
}
|
||||
if (!isChecked) {
|
||||
edit.putBoolean("greeting", false);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
if (prefs.getInt("themeInt", 0) == 0) {
|
||||
darkmode.setChecked(false);
|
||||
}
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
darkmode.setChecked(true);
|
||||
}
|
||||
|
||||
darkmode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.putInt("themeInt", 1);
|
||||
}
|
||||
if (!isChecked) {
|
||||
edit.putInt("themeInt", 0);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
txtClasses.setText(prefs.getString("classes", ""));
|
||||
txtCourses.setText(prefs.getString("courses", ""));
|
||||
|
||||
txtClasses.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
edit.putString("classes", txtClasses.getText().toString());
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
txtCourses.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
edit.putString("courses", txtCourses.getText().toString());
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
if (!prefs.getBoolean("notif", false)) {
|
||||
notifswitch.setChecked(false);
|
||||
}
|
||||
if (prefs.getBoolean("notif", false)) {
|
||||
notifswitch.setChecked(true);
|
||||
}
|
||||
|
||||
notifswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.putBoolean("notif", true);
|
||||
}
|
||||
if (!isChecked) {
|
||||
edit.putBoolean("notif", false);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
if (!prefs.getBoolean("defaultPersonalised", false)) {
|
||||
defaultPlan.setChecked(false);
|
||||
}
|
||||
if (prefs.getBoolean("defaultPersonalised", false)) {
|
||||
defaultPlan.setChecked(true);
|
||||
}
|
||||
|
||||
defaultPlan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.putBoolean("defaultPersonalised", true);
|
||||
}
|
||||
if (!isChecked) {
|
||||
edit.putBoolean("defaultPersonalised", false);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
if (!prefs.getBoolean("openInfo", false)) {
|
||||
openInfo.setChecked(false);
|
||||
}
|
||||
if (prefs.getBoolean("openInfo", false)) {
|
||||
openInfo.setChecked(true);
|
||||
}
|
||||
|
||||
openInfo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.putBoolean("openInfo", true);
|
||||
}
|
||||
if (!isChecked) {
|
||||
edit.putBoolean("openInfo", false);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
if (!prefs.getBoolean("autoRefresh", false)) {
|
||||
autoRefresh.setChecked(false);
|
||||
}
|
||||
if (prefs.getBoolean("autoRefresh", false)) {
|
||||
autoRefresh.setChecked(true);
|
||||
}
|
||||
|
||||
autoRefresh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
edit.putBoolean("autoRefresh", true);
|
||||
}
|
||||
if (!isChecked) {
|
||||
edit.putBoolean("autoRefresh", false);
|
||||
}
|
||||
edit.apply();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO check whether Huawei devices actually support background services
|
||||
|
||||
// DeviceName.with(getContext()).request(new DeviceName.Callback() {
|
||||
// @Override
|
||||
// public void onFinished(DeviceName.DeviceInfo info, Exception error) {
|
||||
// manufacturer = info.manufacturer;
|
||||
// if (manufacturer.contains("Huawei") ||
|
||||
// manufacturer.contains("Honor")) {
|
||||
//// if (true) {
|
||||
// notifswitch.setChecked(false);
|
||||
// autoRefresh.setChecked(true);
|
||||
// notifswitch.setEnabled(false);
|
||||
// autoRefresh.setEnabled(false);
|
||||
//
|
||||
// @ColorInt int color;
|
||||
// if (prefs.getInt("themeInt", 0) == 1) {
|
||||
// TypedValue typedValue = new TypedValue();
|
||||
// Resources.Theme theme = getContext().getTheme();
|
||||
// theme.resolveAttribute(R.attr.colorHintDark, typedValue, true);
|
||||
// color = typedValue.data;
|
||||
// notif2.setTextColor(color);
|
||||
// auto2.setTextColor(color);
|
||||
// } else {
|
||||
// TypedValue typedValue = new TypedValue();
|
||||
// Resources.Theme theme = getContext().getTheme();
|
||||
// theme.resolveAttribute(R.attr.colorHint, typedValue, true);
|
||||
// color = typedValue.data;
|
||||
// }
|
||||
//
|
||||
// notif1.setTextColor(color);
|
||||
// auto1.setTextColor(color);
|
||||
// edit.putBoolean("notif", false);
|
||||
// edit.putBoolean("autoRefresh", true);
|
||||
// edit.apply();
|
||||
// notif2.setText(R.string.chinaNotif);
|
||||
// auto2.setText(R.string.chinaAuto);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
website.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
customTabsIntent.launchUrl(getContext(), Uri.parse("http://307.joomla.schule.bremen.de"));
|
||||
}
|
||||
});
|
||||
|
||||
licences.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle("Licences");
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText("Libraries:\n • Android Device Names © 2015 Jared Rummler, licensed under the Apache License, Version 2.0" +
|
||||
"\n • EasyPreferences © 2018 Mukesh Solanki, licensed under the MIT License" +
|
||||
"\n • jsoup HTML parser © 2009-2018 Jonathan Hedley, licensed under the open source MIT License" +
|
||||
"\n\nFont:\n • Manrope © 2018-2019 Michael Sharanda, licensed under the SIL Open Font License 1.1" +
|
||||
"\n\nIcons:\n • bqlqn\n • fjstudio\n • Freepik\n • Smashicons\n • © 2013-2019 Freepik Company S.L., licensed under Creative Commons BY 3.0" +
|
||||
"\n\nMarketing & Publishing:\n • Leon Becker\n • Alex Lick\n • Batuhan Özcan\n • Erich Kerkesner");
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
tac.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle("Terms & Conditions");
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText("These terms automatically apply to anyone using this app - therefore, please make sure to read them carefully before using the app. Copying or modifying parts of the app or the entire app, as well as creating derivative versions, is prohibited without permission. This app is intellectual property of the developer.\n" +
|
||||
"\n" +
|
||||
"The developer reserves the right to make changes to the app at any given time and for any reason. The user will be informed of any changes made accordingly.\n" +
|
||||
"\n" +
|
||||
"Tampering with the end device, in the form of rooting or otherwise modifying the operating system may result in malfunction of the software. In this case, the developer does not provide support, as the user is responsible for keeping the device free of software that may compromise its security.\n" +
|
||||
"\n" +
|
||||
"Full functionality of the app relies on a steady internet connection. The developer does not take responsibility for malfunction of these services, nor for any errors caused by the end device. The user is responsible for ensuring that their device is fully updated and fully functioning.\n" +
|
||||
"\n" +
|
||||
"As the app relies on third-parties, information provided in-app may be delayed or incorrect at times. The developer accepts no liability for any information mistakenly provided in the app.\n" +
|
||||
"\n" +
|
||||
"The developer may wish to update the app at any point. Should such action arise, then the user is advised to update the app to ensure proper functionality. However, the developer does not promise that the app will be continuously updated, and may stop providing the app at any point. Unless told otherwise, upon any termination, (a) the rights and licenses granted to the user in these terms will end; (b) the user must stop using the app, and (if needed) delete it from their device.\n" +
|
||||
"\n" +
|
||||
"Changes to these Terms & Conditions\n" +
|
||||
"\n" +
|
||||
"The developer may update these Terms & Conditions from time to time. Thus, the user is advised to review this page periodically for any changes. Any changes are effective immediately after they are posted on this page.\n" +
|
||||
"\n" +
|
||||
"Contact Us\n" +
|
||||
"\n" +
|
||||
"In case of questions or suggestions regarding these Terms & Conditions, the user is advised to contact the developer of this app. Contact information is provided through the Play Store.\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"These Terms & Conditions were modified upon the template provided by App Privacy Policy Generator. This service is in no way affiliated with AvH Plan or the developer.");
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
privacy.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder alertDialog;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle("Privacy Policy");
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.simple_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText("The app \"Alexander-von-Humboldt-Plan\", hereby abbreviated to AvH Plan, is provided as a free service by the developer for use as is.\n" +
|
||||
"\n" +
|
||||
"This page is used to inform visitors and users regarding policies with the collection, use, and disclosure of personal information, if they choose to make use of the service.\n" +
|
||||
"\n" +
|
||||
"AvH Plan does not collect, store, share, or in any other way use personal information retrieved from its users. Any information asked for within the app is only used to improve the user experience and as such, is stored locally and cannot be accessed by third-parties or be used to identify the user.\n" +
|
||||
"\n" +
|
||||
"Information Collection and Use\n" +
|
||||
"\n" +
|
||||
"At this moment, AvH Plan does not require personally identifiable information for its core functionality. Certain features do require entering information that may be personally identifiable, however, this data will be retained on the user's device and is therefore not accessible outside the app\n" +
|
||||
"\n" +
|
||||
"Log Data\n" +
|
||||
"\n" +
|
||||
"In the case of an error in the app, device-specific data may be collected and stored on your phone. This data is called Log Data. This Log Data may include information, such as your device's Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilising the service, the time and date when the last usage occured, and other statistics. This data can not be used to personally identify any user.\n" +
|
||||
"\n" +
|
||||
"Cookies\n" +
|
||||
"\n" +
|
||||
"Cookies are files with small amounts of data that are commonly used as anonymous unique identifiers on the web. AvH Plan strives to not make use of cookies for its functionality, however, as its functionality requires access to third-party-websites, cookies may be unintentionally collected by the device's web browser. AvH Plan does not make use of these cookies in any way.\n" +
|
||||
"\n" +
|
||||
"Service Providers\n" +
|
||||
"\n" +
|
||||
"No third-parties are employed for providing any functionality or services of the AvH Plan-app and as such, all functionality is accessible without directly sharing personal data with third-parties.\n" +
|
||||
"\n" +
|
||||
"Security\n" +
|
||||
"\n" +
|
||||
"While absolute security cannot be ensured due to the internet functionality the app employs, no information is shared over any transmission methods.\n" +
|
||||
"\n" +
|
||||
"Links to Other Sites\n" +
|
||||
"\n" +
|
||||
"This Service may contain links to other sites, which are not operated by the developer of AvH Plan. The user is advised to review the privacy policy of any webpage they may access through the app. No responsibility for the content of these third-party websites is provided by the app developer.\n" +
|
||||
"\n" +
|
||||
"Children’s Privacy\n" +
|
||||
"\n" +
|
||||
"The service does not address anyone under the age of 13. As the app does not collect any information from its users, no data is collected from users that may be under the age of 13.\n" +
|
||||
"\n" +
|
||||
"Changes to This Privacy Policy\n" +
|
||||
"\n" +
|
||||
"This privacy policy may be updated as the AvH Plan app is updated with new features. As such, the user is advised to review this page periodically for any changes. Any changes that may be made are effective immediately upon publishing.\n" +
|
||||
"\n" +
|
||||
"Contact Us\n" +
|
||||
"\n" +
|
||||
"In case of questions or suggestions regarding this privacy policy, the user is advised to contact the developer of this app. Contact information is provided through the Play Store.\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"This privacy policy was modified upon the template provided by privacypolicytemplate.net and App Privacy Policy Generator. These services are in no way affiliated with AvH Plan or the developer.");
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
version.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (cs > 0) {
|
||||
cs--;
|
||||
} else {
|
||||
Toast.makeText(getContext(), getString(R.string.donttell), Toast.LENGTH_LONG).show();
|
||||
cs = 7;
|
||||
customTabsIntent.launchUrl(getContext(), Uri.parse("http://www.flussufer.de/gerd/person.htm"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// if (BuildConfig.DEBUG) {
|
||||
// versionNumber.setText(BuildConfig.VERSION_NAME + "-DEV_BUILD");
|
||||
// } else {
|
||||
versionNumber.setText(BuildConfig.VERSION_NAME);
|
||||
// }
|
||||
|
||||
final LinearLayout hiddenBtn = getView().findViewById(R.id.btnHiddenENP);
|
||||
hiddenBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(getActivity(), getString(R.string.bestclass),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
hiddenBtn.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
DeviceName.with(getContext()).request(new DeviceName.Callback() {
|
||||
@Override
|
||||
public void onFinished(DeviceName.DeviceInfo info, Exception error) {
|
||||
name = info.marketName; // "Galaxy S8+"
|
||||
model = info.model; // "SM-G955W"
|
||||
}
|
||||
});
|
||||
AlertDialog.Builder alertDialog;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle(getString(R.string.experimentalmenu));
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.edittext_dialog, null);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText(getString(R.string.fortest));
|
||||
final EditText dialogEditText = dialogView.findViewById(R.id.dialog_edittext);
|
||||
final Button dialogButton = dialogView.findViewById(R.id.dialog_button);
|
||||
dialogButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (dialogEditText.getText().toString().equals("@DEV_DIAGNOSTICS")) {
|
||||
AlertDialog.Builder alertDialogDev;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialogDev = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialogDev = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialogDev.setTitle(getString(R.string.diagnosticsmenu));
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.diagnostics_dialog, null);
|
||||
final TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
setDiagnosticsText(dialogText, prefs);
|
||||
Button launch = dialogView.findViewById(R.id.btnResetLaunch);
|
||||
Button notif = dialogView.findViewById(R.id.btnResetNotif);
|
||||
launch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
edit.putInt("launchDev", 0);
|
||||
edit.apply();
|
||||
setDiagnosticsText(dialogText, prefs);
|
||||
}
|
||||
});
|
||||
notif.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
edit.putInt("notificationTestNumberDev", 0);
|
||||
edit.apply();
|
||||
setDiagnosticsText(dialogText, prefs);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
alertDialogDev.setView(dialogView);
|
||||
alertDialogDev.show();
|
||||
|
||||
} else if (dialogEditText.getText().toString().equals("Tim Bergling")) {
|
||||
Toast.makeText(getActivity(), "◢◤",
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
} else if (dialogEditText.getText().toString().equals("Q1 Matchmaker")) {
|
||||
final Random gen = new Random();
|
||||
AlertDialog.Builder alertDialogDev;
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
alertDialogDev = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
alertDialogDev = new AlertDialog.Builder(getContext(), R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialogDev.setTitle(getString(R.string.dating));
|
||||
View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dating_dialog, null);
|
||||
|
||||
Button datingBtn = dialogView.findViewById(R.id.dating_btn);
|
||||
final EditText boyT = dialogView.findViewById(R.id.dating_txt1);
|
||||
final EditText girlT = dialogView.findViewById(R.id.dating_txt2);
|
||||
final CheckBox boy = dialogView.findViewById(R.id.cb1);
|
||||
final CheckBox girl = dialogView.findViewById(R.id.cb2);
|
||||
final TextView percentage = dialogView.findViewById(R.id.dating_txtp);
|
||||
datingBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
double boyP = 0, girlP = 0, perc = 0;
|
||||
if (boyT.getText().toString().isEmpty() || boy.isChecked()) {
|
||||
boyT.setText(names.boy[gen.nextInt(names.boy.length)]);
|
||||
}
|
||||
if (girlT.getText().toString().isEmpty() || girl.isChecked()) {
|
||||
girlT.setText(names.girl[gen.nextInt(names.girl.length)]);
|
||||
}
|
||||
for (int i = 0; i < boyT.getText().length(); i++) {
|
||||
boyP++;
|
||||
}
|
||||
for (int i = 0; i < girlT.getText().length(); i++) {
|
||||
girlP++;
|
||||
}
|
||||
if (girlP < boyP) {
|
||||
perc = (girlP / boyP) * 100;
|
||||
}
|
||||
if (girlP > boyP) {
|
||||
perc = (boyP / girlP) * 100;
|
||||
}
|
||||
char multiplyTempBoy = boyT.getText().charAt(boyT.getText().length() - 1);
|
||||
char multiplyTempGirl = girlT.getText().charAt(girlT.getText().length() - 1);
|
||||
double multiply = Character.getNumericValue(multiplyTempBoy) + Character.getNumericValue(multiplyTempGirl);
|
||||
multiply = multiply / 1.2;
|
||||
if (perc == 0) {
|
||||
perc += 30;
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
if (perc * (multiply / 40) > 100) {
|
||||
percentage.setText("100.00%");
|
||||
} else {
|
||||
percentage.setText(df.format(perc * (multiply / 40)) + "%");
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
Toast.makeText(getActivity(), getString(R.string.error),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
alertDialogDev.setView(dialogView);
|
||||
alertDialogDev.show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(getActivity(), getString(R.string.nothinghappened),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setDiagnosticsText(TextView dialogText, SharedPreferences prefs) {
|
||||
dialogText.setText("First Launch: " + prefs.getString("firstTimeDev", "") +
|
||||
"\n\nApp launched: " + prefs.getInt("launchDev", 0) +
|
||||
"\n\nNotification Service fired: " + prefs.getInt("notificationTestNumberDev", 0) +
|
||||
"\n\nDevice Name: " + name +
|
||||
"\n\nDevice Model: " + model +
|
||||
"\n\nAndroid Version: " + Build.VERSION.RELEASE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.SearchManager;
|
||||
import android.app.job.JobInfo;
|
||||
import android.app.job.JobScheduler;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.chip.Chip;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.jaredrummler.android.device.DeviceName;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.google.android.material.snackbar.Snackbar.make;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
BottomSheetBehavior bottomSheetBehaviour;
|
||||
private String manufacturer;
|
||||
private String marketName;
|
||||
|
||||
protected void job() {
|
||||
ComponentName componentName = new ComponentName(this, ScheduledJobService.class);
|
||||
JobInfo info = new JobInfo.Builder(42, componentName)
|
||||
.setRequiresCharging(false)
|
||||
.setPersisted(true)
|
||||
.setPeriodic(900000)
|
||||
.build();
|
||||
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
|
||||
scheduler.schedule(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
final Intent firstTime = new Intent(this, FirstTime.class);
|
||||
if (prefs.getBoolean("firstTime", true)) {
|
||||
// if (true) {
|
||||
startActivity(firstTime);
|
||||
finish();
|
||||
}
|
||||
|
||||
edit.putInt("launchDev", prefs.getInt("launchDev", 0) + 1);
|
||||
edit.apply();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
final Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
final AppBarLayout appbarlayout = findViewById(R.id.appbarlayout);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
final TextView toolbarTxt = findViewById(R.id.toolbarTxt);
|
||||
|
||||
final LinearLayout bottomSheetRoot = findViewById(R.id.bottom_sheet);
|
||||
final LinearLayout bottomSheet = findViewById(R.id.bottom_sheet_linear);
|
||||
final TextView bottomSheetHeader = findViewById(R.id.bottom_sheet_header);
|
||||
final TextView bottomSheetText = findViewById(R.id.bottom_sheet_text);
|
||||
final View bottomNavDivider = findViewById(R.id.bottom_nav_divider);
|
||||
bottomSheetBehaviour = BottomSheetBehavior.from(bottomSheetRoot);
|
||||
|
||||
Window window = this.getWindow();
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
// window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
// window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
|
||||
final BottomNavigationView bottomNav = findViewById(R.id.bottom_nav);
|
||||
final Chip chip = findViewById(R.id.chip);
|
||||
|
||||
final CoordinatorLayout fragmentContainer = findViewById(R.id.fragment_container);
|
||||
fragmentContainer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
});
|
||||
|
||||
final LinearLayout bottomSheetCloser = findViewById(R.id.bottom_sheet_closer);
|
||||
bottomSheetBehaviour.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
||||
@Override
|
||||
public void onStateChanged(@NonNull View bottomSheet, int newState) {
|
||||
if (bottomSheetBehaviour.getState() == BottomSheetBehavior.STATE_EXPANDED) { // 2 = expanded, 4 = collapsed
|
||||
bottomSheetCloser.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (bottomSheetBehaviour.getState() == BottomSheetBehavior.STATE_COLLAPSED) { // 2 = expanded, 4 = collapsed
|
||||
bottomSheetCloser.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (!prefs.getBoolean("autoRefresh", false) && prefs.getInt("firstTimeOpening", 0) > 1) {
|
||||
try {
|
||||
final String OLD_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz", NEW_FORMAT = "yyyy-MM-dd, HH:mm:ss";
|
||||
String newDateString;
|
||||
Date d = new Date(prefs.getString("time", ""));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
|
||||
sdf.applyPattern(NEW_FORMAT);
|
||||
newDateString = sdf.format(d);
|
||||
View contextView = findViewById(R.id.coordination);
|
||||
Snackbar snackbar = make(contextView, getText(R.string.lastupdated) + ": " + newDateString, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null);
|
||||
snackbar.show();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final Context context = this;
|
||||
|
||||
// TODO Huawei dialog
|
||||
|
||||
if (prefs.getBoolean("huaweiDeviceDialog", true)) {
|
||||
// if (true) {
|
||||
DeviceName.with(this).request(new DeviceName.Callback() {
|
||||
@Override
|
||||
public void onFinished(DeviceName.DeviceInfo info, Exception error) {
|
||||
manufacturer = info.manufacturer;
|
||||
marketName = info.marketName;
|
||||
if (manufacturer.contains("Huawei") ||
|
||||
manufacturer.contains("Honor") ||
|
||||
manufacturer.contains("Xiaomi")) {
|
||||
// if (true) {
|
||||
|
||||
AlertDialog.Builder alertDialog;
|
||||
View dialogView = LayoutInflater.from(context).inflate(R.layout.secret_dialog, null);
|
||||
TextView secretText = dialogView.findViewById(R.id.secrettext);
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
secretText.setTextColor(getResources().getColor(R.color.hintdark));
|
||||
alertDialog = new AlertDialog.Builder(context, R.style.AlertDialogCustomDark);
|
||||
} else {
|
||||
secretText.setTextColor(getResources().getColor(R.color.hint));
|
||||
alertDialog = new AlertDialog.Builder(context, R.style.AlertDialogCustomLight);
|
||||
}
|
||||
alertDialog.setTitle(R.string.chinaTitle);
|
||||
TextView dialogText = dialogView.findViewById(R.id.dialogtext);
|
||||
dialogText.setText(R.string.chinaDialog);
|
||||
secretText.setText(R.string.orbuy);
|
||||
Button searchbtn = dialogView.findViewById(R.id.searchbtn);
|
||||
searchbtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
|
||||
intent.putExtra(SearchManager.QUERY, marketName + " disable power optimisation");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
alertDialog.setView(dialogView);
|
||||
alertDialog.show();
|
||||
|
||||
edit.putBoolean("huaweiDeviceDialog", false);
|
||||
edit.apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
|
||||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
|
||||
} else {
|
||||
View contextView = findViewById(R.id.coordination);
|
||||
Snackbar.make(contextView, getText(R.string.nointernet), Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
bottomSheetCloser.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
bottomSheetCloser.setVisibility(View.GONE);
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
});
|
||||
|
||||
// theme change
|
||||
if (prefs.getInt("themeInt", 0) == 0) {
|
||||
setTheme(R.style.AppTheme0);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
window.setStatusBarColor(ContextCompat.getColor(this, R.color.white));
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.white));
|
||||
window.setNavigationBarColor(ContextCompat.getColor(this, R.color.white));
|
||||
} else {
|
||||
window.setStatusBarColor(ContextCompat.getColor(this, R.color.black));
|
||||
window.setNavigationBarColor(ContextCompat.getColor(this, R.color.black));
|
||||
}
|
||||
|
||||
toolbarTxt.setTextColor(ContextCompat.getColor(this, R.color.accent));
|
||||
bottomNav.setBackgroundColor(ContextCompat.getColor(this, R.color.white));
|
||||
chip.setChipBackgroundColor(getResources().getColorStateList(R.color.chip_state_list));
|
||||
chip.setTextColor(ContextCompat.getColor(this, R.color.lessdark));
|
||||
bottomSheet.setBackgroundColor(ContextCompat.getColor(this, R.color.white));
|
||||
bottomSheetHeader.setTextColor(ContextCompat.getColor(this, R.color.lessdark));
|
||||
bottomSheetText.setTextColor(ContextCompat.getColor(this, R.color.lessdark));
|
||||
bottomNavDivider.setBackgroundColor(ContextCompat.getColor(this, R.color.lightgrey));
|
||||
|
||||
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
|
||||
ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, ContextCompat.getColor(this, R.color.white));
|
||||
setTaskDescription(taskDesc);
|
||||
}
|
||||
if (prefs.getInt("themeInt", 0) == 1) {
|
||||
setTheme(R.style.AppTheme0Dark);
|
||||
window.setStatusBarColor(ContextCompat.getColor(this, R.color.background));
|
||||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.dark));
|
||||
toolbarTxt.setTextColor(ContextCompat.getColor(this, R.color.accent));
|
||||
bottomNav.setBackgroundColor(ContextCompat.getColor(this, R.color.dark));
|
||||
window.setNavigationBarColor(getResources().getColor(R.color.background));
|
||||
chip.setChipBackgroundColor(getResources().getColorStateList(R.color.chip_state_list_dark));
|
||||
chip.setTextColor(ContextCompat.getColor(this, R.color.lightgrey));
|
||||
bottomSheet.setBackgroundColor(ContextCompat.getColor(this, R.color.dark));
|
||||
bottomSheetHeader.setTextColor(ContextCompat.getColor(this, R.color.lightgrey));
|
||||
bottomSheetText.setTextColor(ContextCompat.getColor(this, R.color.lightgrey));
|
||||
bottomNavDivider.setBackgroundColor(ContextCompat.getColor(this, R.color.darkdivider));
|
||||
|
||||
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
|
||||
ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(getString(R.string.app_name), bm, getResources().getColor(R.color.background));
|
||||
setTaskDescription(taskDesc);
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("greeting", false)) {
|
||||
if (!prefs.getString("username", "").isEmpty()) {
|
||||
final Animation animationIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.chip_slide_in);
|
||||
final Animation animationOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.chip_slide_out);
|
||||
final Random generator = new Random();
|
||||
Resources res = getResources();
|
||||
String greetings[] = res.getStringArray(R.array.greeting8_array);
|
||||
Calendar rightNow = Calendar.getInstance();
|
||||
int currentHour = rightNow.get(Calendar.HOUR_OF_DAY);
|
||||
|
||||
switch (generator.nextInt(9)) {
|
||||
case 0:
|
||||
chip.setText(getString(R.string.greeting0, prefs.getString("username", "")));
|
||||
break;
|
||||
case 1:
|
||||
chip.setText(getString(R.string.greeting1, prefs.getString("username", "")));
|
||||
break;
|
||||
case 2:
|
||||
chip.setText(getString(R.string.greeting2, prefs.getString("username", "")));
|
||||
break;
|
||||
case 3:
|
||||
chip.setText(getString(R.string.greeting3, prefs.getString("username", "")));
|
||||
break;
|
||||
case 4:
|
||||
chip.setText(getString(R.string.greeting4, prefs.getString("username", "")));
|
||||
break;
|
||||
case 5:
|
||||
chip.setText(getString(R.string.greeting5, prefs.getString("username", "")));
|
||||
break;
|
||||
case 6:
|
||||
chip.setText(getString(R.string.greeting6, prefs.getString("username", "")));
|
||||
break;
|
||||
case 7:
|
||||
chip.setText(getString(R.string.greeting7, prefs.getString("username", "")));
|
||||
break;
|
||||
case 8:
|
||||
if (currentHour < 11) {
|
||||
chip.setText(greetings[0] + prefs.getString("username", "") + ".");
|
||||
} else if (currentHour > 10 && currentHour < 18) {
|
||||
chip.setText(greetings[1] + prefs.getString("username", "") + ".");
|
||||
} else if (currentHour > 17) {
|
||||
chip.setText(greetings[2] + prefs.getString("username", "") + ".");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
final Handler chipIn = new Handler();
|
||||
chipIn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chip.setVisibility(View.VISIBLE);
|
||||
chip.startAnimation(animationIn);
|
||||
}
|
||||
}, 500);
|
||||
|
||||
final Handler chipOut = new Handler();
|
||||
chipOut.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chip.startAnimation(animationOut);
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
animationOut.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation arg0) {}
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation arg0) {}
|
||||
@Override
|
||||
public void onAnimationEnd(Animation arg0) {
|
||||
chip.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.getInt("firstTimeOpening", 0) < 2) {
|
||||
// if (true) {
|
||||
final Handler bsbIn = new Handler();
|
||||
bsbIn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}
|
||||
}, 600);
|
||||
|
||||
final Handler bsbOut = new Handler();
|
||||
bsbOut.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
}, 2000);
|
||||
|
||||
edit.putInt("firstTimeOpening", prefs.getInt("firstTimeOpening", 0) + 1);
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("openInfo", false)) {
|
||||
final Handler bsbIn = new Handler();
|
||||
bsbIn.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}
|
||||
}, 600);
|
||||
}
|
||||
|
||||
|
||||
if (prefs.getBoolean("defaultPersonalised", false)) {
|
||||
loadFragment(new FragmentPersonal());
|
||||
bottomNav.setSelectedItemId(R.id.personal);
|
||||
if (!prefs.getString("username", "").isEmpty()) {
|
||||
if (Character.toString(prefs.getString("username", "").charAt(prefs.getString("username", "").length() - 1)).toLowerCase().equals("s")
|
||||
|| Character.toString(prefs.getString("username", "").charAt(prefs.getString("username", "").length() - 1)).toLowerCase().equals("z")) {
|
||||
toolbarTxt.setText(prefs.getString("username", "") + getString(R.string.nosplan));
|
||||
} else {
|
||||
toolbarTxt.setText(prefs.getString("username", "") + getString(R.string.splan));
|
||||
}
|
||||
} else {
|
||||
toolbarTxt.setText(getString(R.string.personalplan));
|
||||
}
|
||||
} else if (!prefs.getBoolean("defaultPersonalised", false)) {
|
||||
loadFragment(new FragmentPlan());
|
||||
bottomNav.setSelectedItemId(R.id.plan);
|
||||
toolbarTxt.setText(getString(R.string.app_name));
|
||||
}
|
||||
|
||||
job();
|
||||
|
||||
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
Fragment fragment = null;
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.plan:
|
||||
fragment = new FragmentPlan();
|
||||
toolbarTxt.setText(getString(R.string.app_name));
|
||||
break;
|
||||
case R.id.personal:
|
||||
fragment = new FragmentPersonal();
|
||||
if (!prefs.getString("username", "").isEmpty()) {
|
||||
if (Character.toString(prefs.getString("username", "").charAt(prefs.getString("username", "").length() - 1)).toLowerCase().equals("s")
|
||||
|| Character.toString(prefs.getString("username", "").charAt(prefs.getString("username", "").length() - 1)).toLowerCase().equals("x")
|
||||
|| Character.toString(prefs.getString("username", "").charAt(prefs.getString("username", "").length() - 1)).toLowerCase().equals("z")) {
|
||||
toolbarTxt.setText(prefs.getString("username", "") + getString(R.string.nosplan));
|
||||
} else {
|
||||
toolbarTxt.setText(prefs.getString("username", "") + getString(R.string.splan));
|
||||
}
|
||||
} else {
|
||||
toolbarTxt.setText(getString(R.string.personalplan));
|
||||
}
|
||||
break;
|
||||
// case R.id.search:
|
||||
// fragment = new FragmentSearch();
|
||||
// toolbarTxt.setText(getString(R.string.search));
|
||||
// break;
|
||||
case R.id.menu:
|
||||
fragment = new FragmentFood();
|
||||
toolbarTxt.setText(getString(R.string.foodmenu));
|
||||
break;
|
||||
case R.id.settings:
|
||||
fragment = new FragmentSettings();
|
||||
toolbarTxt.setText(getString(R.string.settings));
|
||||
break;
|
||||
}
|
||||
appbarlayout.setExpanded(true);
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
return loadFragment(fragment);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private boolean loadFragment(Fragment fragment) {
|
||||
if (fragment != null) {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
// .setCustomAnimations(R.anim.fade_in, R.anim.fade_out) // TODO add proper animations
|
||||
.replace(R.id.fragment_container, fragment)
|
||||
.commit();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (bottomSheetBehaviour.getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
bottomSheetBehaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public class PlanCard {
|
||||
private Drawable mIcon;
|
||||
private String mGroup, mDate, mTime, mCourse, mRoom, mAdditional;
|
||||
|
||||
public PlanCard(Drawable icon, String group, String date, String time, String course, String room, String additional) {
|
||||
mIcon = icon;
|
||||
mGroup = group;
|
||||
mDate = date;
|
||||
mTime = time;
|
||||
mCourse = course;
|
||||
mRoom = room;
|
||||
mAdditional = additional;
|
||||
}
|
||||
|
||||
public Drawable getImageResource() {
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return mGroup;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return mDate;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return mTime;
|
||||
}
|
||||
|
||||
public String getCourse() {
|
||||
return mCourse;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return mRoom;
|
||||
}
|
||||
|
||||
public String getAdditional() {
|
||||
return mAdditional;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.job.JobParameters;
|
||||
import android.app.job.JobService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.madapps.prefrences.EasyPrefrences;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ScheduledJobService extends JobService {
|
||||
|
||||
private boolean jobCancelled = false;
|
||||
Context context = this;
|
||||
private SubstViewModel substViewModel;
|
||||
|
||||
@Override
|
||||
public boolean onStartJob(JobParameters params) {
|
||||
doBackgroundWork(params);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void doBackgroundWork(final JobParameters params) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
substViewModel = new SubstViewModel(getApplication());
|
||||
// substViewModel = ViewModelProviders.of().get(SubstViewModel.class);
|
||||
// substViewModel.getAllSubst().observe(this, new Observer<List<Subst>>() {
|
||||
// @Override
|
||||
// public void onChanged(List<Subst> substs) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (jobCancelled) {
|
||||
return;
|
||||
}
|
||||
if (prefs.getBoolean("notif", false)) {
|
||||
edit.putInt("notificationTestNumberDev", prefs.getInt("notificationTestNumberDev", 0) + 1);
|
||||
edit.apply();
|
||||
URL url;
|
||||
URLConnection connection = null;
|
||||
try {
|
||||
url = new URL("https://djd4rkn355.github.io/subst");
|
||||
connection = url.openConnection();
|
||||
} catch (MalformedURLException e) {}
|
||||
catch (IOException e) {}
|
||||
try {
|
||||
if ((!connection.getHeaderField("Last-Modified").equals(prefs.getString("time", "")))) {
|
||||
// if (true) {
|
||||
new fetcher(context).execute();
|
||||
edit.putString("time", connection.getHeaderField("Last-Modified"));
|
||||
edit.apply();
|
||||
}
|
||||
} catch (NullPointerException e1) {
|
||||
}
|
||||
}
|
||||
jobFinished(params, false);
|
||||
}
|
||||
}).start();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onStopJob(JobParameters params) {
|
||||
jobCancelled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private class fetcher extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private int count = 0, columns = 0, pCount = 0, priority = 200;
|
||||
Context mContext;
|
||||
String notifText = "", foodInfo = "", informational = "";
|
||||
String[] groupS, dateS, timeS, courseS, roomS, additionalS;
|
||||
boolean attempt = false, emptyIcon;
|
||||
URL url;
|
||||
URLConnection connection;
|
||||
String modified;
|
||||
Elements rows, paragraphs;
|
||||
Elements[] paragraphsFood = new Elements[2];
|
||||
Elements foodElements;
|
||||
Element[] dateFood = new Element[2], blockFood = new Element[2];
|
||||
Document doc, docFood;
|
||||
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
String channelId = "general";
|
||||
CharSequence channelName = getText(R.string.general);
|
||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
||||
NotificationChannel channel;
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
final SharedPreferences.Editor edit = prefs.edit();
|
||||
|
||||
protected fetcher(Context mContext) {
|
||||
this.mContext = mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
channel = new NotificationChannel(channelId, channelName, importance);
|
||||
channel.enableLights(true);
|
||||
channel.setLightColor(Color.BLUE);
|
||||
manager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
try {
|
||||
doc = Jsoup.connect("https://djd4rkn355.github.io/subst").get();
|
||||
url = new URL("https://djd4rkn355.github.io/subst");
|
||||
connection = url.openConnection();
|
||||
rows = doc.select("tr");
|
||||
count = rows.size();
|
||||
|
||||
docFood = Jsoup.connect("https://djd4rkn355.github.io/food.html").get();
|
||||
foodElements = docFood.select("th");
|
||||
|
||||
paragraphs = doc.select("p");
|
||||
pCount = paragraphs.size();
|
||||
|
||||
for (int i = 0; i < pCount; i++) {
|
||||
if (i == 0) {
|
||||
informational = paragraphs.get(i).text();
|
||||
} else {
|
||||
informational += "\n\n" + paragraphs.get(i).text();
|
||||
}
|
||||
}
|
||||
|
||||
edit.putString("informational", informational);
|
||||
edit.apply();
|
||||
|
||||
attempt = true;
|
||||
modified = connection.getHeaderField("Last-Modified");
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
groupS = new String[count];
|
||||
dateS = new String[count];
|
||||
timeS = new String[count];
|
||||
courseS = new String[count];
|
||||
roomS = new String[count];
|
||||
additionalS = new String[count];
|
||||
|
||||
if (attempt) {
|
||||
|
||||
EasyPrefrences easyPrefs = new EasyPrefrences(context);
|
||||
ArrayList<String> foodList = new ArrayList<>();
|
||||
for (int foodInt = 0; foodInt < foodElements.size(); foodInt++) {
|
||||
|
||||
try {
|
||||
if (foodElements.get(foodInt).text().contains("Montag") ||
|
||||
foodElements.get(foodInt).text().contains("Dienstag") ||
|
||||
foodElements.get(foodInt).text().contains("Mittwoch") ||
|
||||
foodElements.get(foodInt).text().contains("Donnerstag") ||
|
||||
foodElements.get(foodInt).text().contains("Freitag")) {
|
||||
|
||||
if (foodElements.get(foodInt + 3).text().contains("Montag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Dienstag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Mittwoch") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Donnerstag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("Freitag") ||
|
||||
foodElements.get(foodInt + 3).text().contains("von")) {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text() + "\n" + foodElements.get(foodInt + 2).text());
|
||||
foodInt += 2;
|
||||
} else if (foodElements.get(foodInt + 2).text().contains("Montag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Dienstag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Mittwoch") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Donnerstag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("Freitag") ||
|
||||
foodElements.get(foodInt + 2).text().contains("von")) {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text());
|
||||
foodInt += 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
foodList.add(foodElements.get(foodInt).text());
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
try {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text() + "\n" + foodElements.get(foodInt + 2).text());
|
||||
break;
|
||||
} catch (IndexOutOfBoundsException e1) {
|
||||
foodList.add(foodElements.get(foodInt).text() + "\n" + foodElements.get(foodInt + 1).text());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
easyPrefs.putListString("foodListPrefs", foodList);
|
||||
|
||||
if (substViewModel != null) {
|
||||
substViewModel.deleteAllSubst();
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
Element row = rows.get(i);
|
||||
Elements cols = row.select("th");
|
||||
groupS[i] = cols.get(0).text();
|
||||
dateS[i] = cols.get(1).text();
|
||||
timeS[i] = cols.get(2).text();
|
||||
courseS[i] = cols.get(3).text();
|
||||
roomS[i] = cols.get(4).text();
|
||||
additionalS[i] = cols.get(5).text();
|
||||
|
||||
int drawable = icons(courseS[i]);
|
||||
Subst subst = new Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i], roomS[i], additionalS[i], priority);
|
||||
priority--;
|
||||
substViewModel.insert(subst);
|
||||
|
||||
// for juniors
|
||||
if (prefs.getString("courses", "").isEmpty() && !prefs.getString("classes", "").isEmpty()) {
|
||||
if (!groupS[i].isEmpty() && !groupS[i].equals("")) {
|
||||
if (prefs.getString("classes", "").contains(groupS[i]) || groupS[i].contains(prefs.getString("classes", ""))) {
|
||||
if (!notifText.isEmpty()) {
|
||||
notifText += ", ";
|
||||
}
|
||||
notifText += courseS[i] + ": " + additionalS[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for seniors
|
||||
else if (!prefs.getString("courses", "").isEmpty() && !prefs.getString("classes", "").isEmpty()) {
|
||||
if (!groupS[i].equals("") && !courseS[i].equals("")) {
|
||||
if (prefs.getString("courses", "").contains(courseS[i])) {
|
||||
if (prefs.getString("classes", "").contains(groupS[i]) || groupS[i].contains(prefs.getString("classes", ""))) {
|
||||
if (!notifText.isEmpty()) {
|
||||
notifText += ", ";
|
||||
}
|
||||
notifText += courseS[i] + ": " + additionalS[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent openApp = new Intent(getApplicationContext(), MainActivity.class);
|
||||
openApp.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent openAppPending = PendingIntent.getActivity(mContext, 0, openApp, 0);
|
||||
|
||||
if (!notifText.isEmpty()) {
|
||||
Notification notification = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
notification = new NotificationCompat.Builder(mContext)
|
||||
.setContentTitle(getString(R.string.subst))
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(notifText))
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setChannelId(channelId)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.build();
|
||||
} else {
|
||||
notification = new NotificationCompat.Builder(mContext)
|
||||
.setContentTitle(getString(R.string.subst))
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(notifText))
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.build();
|
||||
}
|
||||
manager.notify(1, notification);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int icons(String course) {
|
||||
emptyIcon = false;
|
||||
if (course.toLowerCase().contains("deu") || course.toLowerCase().contains("dep") || course.toLowerCase().contains("daz")) {
|
||||
return R.drawable.ic_german;
|
||||
} else if (course.toLowerCase().contains("mat") || course.toLowerCase().contains("map")) {
|
||||
return R.drawable.ic_maths;
|
||||
} else if (course.toLowerCase().contains("eng") || course.toLowerCase().contains("enp") || course.toLowerCase().contains("ena")) {
|
||||
return R.drawable.ic_english;
|
||||
} else if (course.toLowerCase().contains("spo") || course.toLowerCase().contains("spp") || course.toLowerCase().contains("spth")) {
|
||||
return R.drawable.ic_pe;
|
||||
} else if (course.toLowerCase().contains("pol") || course.toLowerCase().contains("pop")) {
|
||||
return R.drawable.ic_politics;
|
||||
} else if (course.toLowerCase().contains("dar") || course.toLowerCase().contains("dap")) {
|
||||
return R.drawable.ic_drama;
|
||||
} else if (course.toLowerCase().contains("phy") || course.toLowerCase().contains("php")) {
|
||||
return R.drawable.ic_physics;
|
||||
} else if (course.toLowerCase().contains("bio") || course.toLowerCase().contains("bip") || course.toLowerCase().contains("nw")) {
|
||||
return R.drawable.ic_biology;
|
||||
} else if (course.toLowerCase().contains("che") || course.toLowerCase().contains("chp")) {
|
||||
return R.drawable.ic_chemistry;
|
||||
} else if (course.toLowerCase().contains("phi") || course.toLowerCase().contains("psp")) {
|
||||
return R.drawable.ic_philosophy;
|
||||
} else if (course.toLowerCase().contains("laa") || course.toLowerCase().contains("laf") || course.toLowerCase().contains("lat")) {
|
||||
return R.drawable.ic_latin;
|
||||
} else if (course.toLowerCase().contains("spa") || course.toLowerCase().contains("spf")) {
|
||||
return R.drawable.ic_spanish;
|
||||
} else if (course.toLowerCase().contains("fra") || course.toLowerCase().contains("frf") || course.toLowerCase().contains("frz")) {
|
||||
return R.drawable.ic_french;
|
||||
} else if (course.toLowerCase().contains("inf")) {
|
||||
return R.drawable.ic_compsci;
|
||||
} else if (course.toLowerCase().contains("ges")) {
|
||||
return R.drawable.ic_history;
|
||||
} else if (course.toLowerCase().contains("rel")) {
|
||||
return R.drawable.ic_religion;
|
||||
} else if (course.toLowerCase().contains("geg") || course.toLowerCase().contains("wuk")) {
|
||||
return R.drawable.ic_geography;
|
||||
} else if (course.toLowerCase().contains("kun")) {
|
||||
return R.drawable.ic_arts;
|
||||
} else if (course.toLowerCase().contains("mus")) {
|
||||
return R.drawable.ic_music;
|
||||
} else if (course.toLowerCase().contains("tue")) {
|
||||
return R.drawable.ic_turkish;
|
||||
} else if (course.toLowerCase().contains("chi")) {
|
||||
return R.drawable.ic_chinese;
|
||||
} else if (course.toLowerCase().contains("gll")) {
|
||||
return R.drawable.ic_gll;
|
||||
} else if (course.toLowerCase().contains("wat")) {
|
||||
return R.drawable.ic_wat;
|
||||
} else if (course.toLowerCase().contains("för")) {
|
||||
return R.drawable.ic_help;
|
||||
} else if (course.toLowerCase().contains("wp") || course.toLowerCase().contains("met")) {
|
||||
return R.drawable.ic_pencil;
|
||||
} else {
|
||||
emptyIcon = true;
|
||||
return R.drawable.ic_empty;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
@Entity(tableName = "subst_table")
|
||||
public class Subst {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private int id;
|
||||
|
||||
private int icon;
|
||||
private String group, date, time, course, room, additional;
|
||||
private int priority;
|
||||
|
||||
public Subst(int icon, String group, String date, String time, String course, String room, String additional, int priority) {
|
||||
this.icon = icon;
|
||||
this.group = group;
|
||||
this.date = date;
|
||||
this.time = time;
|
||||
this.course = course;
|
||||
this.room = room;
|
||||
this.additional = additional;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public String getCourse() {
|
||||
return course;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public String getAdditional() {
|
||||
return additional;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Update;
|
||||
|
||||
@Dao
|
||||
public interface SubstDao {
|
||||
|
||||
@Insert
|
||||
void insert(Subst subst);
|
||||
|
||||
@Update
|
||||
void update(Subst subst);
|
||||
|
||||
@Delete
|
||||
void delete(Subst subst);
|
||||
|
||||
@Query("DELETE FROM subst_table")
|
||||
void deleteAllSubst();
|
||||
|
||||
@Query("SELECT * FROM subst_table ORDER BY priority DESC")
|
||||
LiveData<List<Subst>> getAllSubst();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
@Database(entities = {Subst.class}, version = 2, exportSchema = false)
|
||||
public abstract class SubstDatabase extends RoomDatabase {
|
||||
|
||||
private static SubstDatabase instance;
|
||||
|
||||
public abstract SubstDao substDao();
|
||||
|
||||
public static synchronized SubstDatabase getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = Room.databaseBuilder(context.getApplicationContext(),
|
||||
SubstDatabase.class,
|
||||
"subst_database")
|
||||
.fallbackToDestructiveMigration()
|
||||
.build();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
// private static RoomDatabase.Callback roomCallback = new RoomDatabase.Callback() { // initial population
|
||||
// @Override
|
||||
// public void onCreate(@NonNull SupportSQLiteDatabase db) {
|
||||
// super.onCreate(db);
|
||||
// new PopulateDBAsync(instance).execute();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// private static class PopulateDBAsync extends AsyncTask<Void, Void, Void> {
|
||||
//
|
||||
// private SubstDao substDao;
|
||||
//
|
||||
// private PopulateDBAsync(SubstDatabase db) {
|
||||
// substDao = db.substDao();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground(Void... voids) {
|
||||
// substDao.insert(new Subst(R.drawable.ic_avh,"Group", "Date", "Time", "Course", "Room", "Additional", 0));
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
public class SubstRepository {
|
||||
|
||||
private SubstDao substDao;
|
||||
private LiveData<List<Subst>> allSubst;
|
||||
|
||||
public SubstRepository(Application application) {
|
||||
SubstDatabase database = SubstDatabase.getInstance(application);
|
||||
substDao = database.substDao();
|
||||
allSubst = substDao.getAllSubst();
|
||||
}
|
||||
|
||||
public void insert(Subst subst) {
|
||||
new InsertSubstAsync(substDao).execute(subst);
|
||||
}
|
||||
|
||||
public void update(Subst subst) {
|
||||
new UpdateSubstAsync(substDao).execute(subst);
|
||||
}
|
||||
|
||||
public void delete(Subst subst) {
|
||||
new DeleteSubstAsync(substDao).execute(subst);
|
||||
}
|
||||
|
||||
public void deleteAllSubst() {
|
||||
new DeleteAllSubstAsync(substDao).execute();
|
||||
}
|
||||
|
||||
public LiveData<List<Subst>> getAllSubst() {
|
||||
return allSubst;
|
||||
}
|
||||
|
||||
private static class InsertSubstAsync extends AsyncTask<Subst, Void, Void> {
|
||||
|
||||
private SubstDao substDao;
|
||||
private InsertSubstAsync(SubstDao substDao) {
|
||||
this.substDao = substDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Subst... substs) {
|
||||
substDao.insert(substs[0]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class UpdateSubstAsync extends AsyncTask<Subst, Void, Void> {
|
||||
|
||||
private SubstDao substDao;
|
||||
private UpdateSubstAsync(SubstDao substDao) {
|
||||
this.substDao = substDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Subst... substs) {
|
||||
substDao.update(substs[0]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteSubstAsync extends AsyncTask<Subst, Void, Void> {
|
||||
|
||||
private SubstDao substDao;
|
||||
private DeleteSubstAsync(SubstDao substDao) {
|
||||
this.substDao = substDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Subst... substs) {
|
||||
substDao.delete(substs[0]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteAllSubstAsync extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private SubstDao substDao;
|
||||
private DeleteAllSubstAsync(SubstDao substDao) {
|
||||
this.substDao = substDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
substDao.deleteAllSubst();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
public class SubstViewModel extends AndroidViewModel {
|
||||
|
||||
private SubstRepository repository;
|
||||
private LiveData<List<Subst>> allSubst;
|
||||
|
||||
public SubstViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
repository = new SubstRepository(application);
|
||||
allSubst = repository.getAllSubst();
|
||||
}
|
||||
|
||||
public void insert(Subst subst) {
|
||||
repository.insert(subst);
|
||||
}
|
||||
|
||||
public void update(Subst subst) {
|
||||
repository.update(subst);
|
||||
}
|
||||
|
||||
public void delete(Subst subst) {
|
||||
repository.delete(subst);
|
||||
}
|
||||
|
||||
public void deleteAllSubst() {
|
||||
repository.deleteAllSubst();
|
||||
}
|
||||
|
||||
public LiveData<List<Subst>> getAllSubst() {
|
||||
return allSubst;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.denizd.substitutionplan;
|
||||
|
||||
public class names {
|
||||
protected static String boy[] = { "Cedric Grislawski", // excluded are most boys from Physical Education
|
||||
// profile (no offense) and me
|
||||
"Dawid Kniola", "Jonas Köstergarten", "Jakob Moerschner", "Siamak Nemati", "Hendrik Plönnings",
|
||||
"Jan Rohmann", "Anton Rosenberger", "Christoph Senft", "Jan Mika Sieckendieck", "Alexander Sinaj",
|
||||
"Nico Tischer", "Nhat Vinh Tran", "Leon Becker", "Youssef Beltagi", "Erich Kerkesner", "Alex Lick",
|
||||
"Oskar Piskorz", "Theo Recktor", "Eray Vatansever", "Dennis Wojciechowski", "Übeydullah Alkan",
|
||||
"Yahya Almarashli", "Sinan Aydin", "Rick Büteröwe", "Levin Dropp", "Silvester Jermolajew", "Tolgay Kekilli",
|
||||
"Dennis Lange", "Aras Mahmoud", "Batuhan Özcan", "Michael Rek", "Khabat Sharif", "Anbinh Tran",
|
||||
"Bastian Westerboer", "Abdulwahab Alshebli", "Kelechi Gaius", "Armin Großmann", "Anes Halep",
|
||||
"Marco Jankowski", "Emirhan Kaplan", "Alexander Kofmann", "Tobi Derek Köhler", "Vasilije Nedeljkovic",
|
||||
"Batu Öcal", "Paul Rehbohm" };
|
||||
protected static String girl[] = { "Mayra Dronia", // excluded are the girls from Physical Education profile
|
||||
// (no offense)
|
||||
"Shalin Ramadan", "Nigina Amin", "Mariya Kheder", "Niegen Khosrawi", "Dayana Osipova",
|
||||
"Julia Petri", "Laura Pister", "Dana Alyoussef", "Ilkem Kahramanoglu", "Rozita Amiri", "Mirja Arneke",
|
||||
"Nastasja Banik", "Anni Kienke", "Benedite Mateta", "Leonie Pohl", "Cecillia Sawires", "Patrycja Smółka",
|
||||
"Elif Zencirkiran", "Nusyba Al Semadi", "Vivien Bruns", "Yasemin Dal", "Svenja Demuth", "Nina Groß",
|
||||
"Kim Lahmeyer", "Luca Minschke", "Kim Reschke", "Amélie Schnellecke", "Delal Secer", "Xenia Segijanski",
|
||||
"Melisa Tas", "Kim Völker", "Banu Yari", "Zeinab Ali", "Mariam Bannout", "Stefanie Fahl", "Yamaty Gaye",
|
||||
"Anna-Sophia Haeberle", "Finja Hastedt", "Viktoria Hammermeister", "Isabel Horn", "Laura Kern",
|
||||
"Melanie Kleinermann", "Målin Kollhoff", "Darja Maier", "Lisa Maier", "Naura Nadzifah", "Janina Roelfs",
|
||||
"Vanessa Scheifler", "Mara Thies", "Lieli Umar", "Leonie Welk", "Betraben Yacoub" };
|
||||
}
|
||||
Reference in New Issue
Block a user