Skip to content
Snippets Groups Projects
Commit f8c63977 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Added a lot of chat view related code

parent 84438b3d
No related branches found
No related tags found
No related merge requests found
Showing
with 531 additions and 25 deletions
package de.kuschku.quasseldroid_ng;
package de.kuschku.quasseldroid_ng.ui;
import com.mikepenz.materialdrawer.holder.StringHolder;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
......
package de.kuschku.quasseldroid_ng.util;
import android.os.Build;
public class CompatibilityUtils {
private CompatibilityUtils() {
}
public static boolean isChromiumDevice() {
return (Build.MANUFACTURER.toLowerCase().contains("chromium") && Build.BRAND.toLowerCase().contains("chromium"));
}
}
package de.kuschku.quasseldroid_ng.util;
import android.content.Context;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.text.SimpleDateFormat;
public class DateFormatHelper {
private DateFormatHelper() {
}
public static DateTimeFormatter getTimeFormatter(Context ctx) {
return DateTimeFormat.forPattern(((SimpleDateFormat) android.text.format.DateFormat.getTimeFormat(ctx)).toLocalizedPattern());
}
}
package de.kuschku.quasseldroid_ng.util;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
public class IrcFormatHelper {
private final ThemeUtil.Colors colors;
public IrcFormatHelper(ThemeUtil.Colors colors) {
this.colors = colors;
}
public CharSequence formatUserNick(String nick) {
int colorIndex = IrcUserUtils.getSenderColor(nick);
int color = colors.senderColors[colorIndex];
SpannableString str = new SpannableString(nick);
str.setSpan(new ForegroundColorSpan(color), 0, nick.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
str.setSpan(new StyleSpan(Typeface.BOLD), 0, nick.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return str;
}
public CharSequence formatIrcMessage(String message) {
SpannableString str = new SpannableString(message);
return str;
}
}
package de.kuschku.util;
package de.kuschku.quasseldroid_ng.util;
import java.nio.charset.Charset;
import java.util.Locale;
......@@ -70,10 +70,15 @@ public class IrcUserUtils {
}
public static String getUser(String hostmask) {
return hostmask.split("!")[1].split("@")[0];
return getMask(hostmask).split("@")[0];
}
public static String getHost(String hostmask) {
return hostmask.split("@")[1];
return getMask(hostmask).split("@")[1];
}
public static String getMask(String hostmask) {
return hostmask.split("!")[1];
}
}
\ No newline at end of file
package de.kuschku.quasseldroid_ng.utils;
package de.kuschku.quasseldroid_ng.util;
public class ServerAddress {
public final String host;
......
/*
* Copyright © 2014 George T. Steel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.kuschku.quasseldroid_ng.util;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.Spannable;
/**
* Provides {@link String#format} style functions that work with {@link Spanned} strings and preserve formatting.
*
* @author George T. Steel
*
*/
public class SpanFormatter {
public static final Pattern FORMAT_SEQUENCE = Pattern.compile("%([0-9]+\\$|<?)([^a-zA-z%]*)([[a-zA-Z%]&&[^tT]]|[tT][a-zA-Z])");
private SpanFormatter(){}
/**
* Version of {@link String#format(String, Object...)} that works on {@link Spanned} strings to preserve rich text formatting.
* Both the {@code format} as well as any {@code %s args} can be Spanned and will have their formatting preserved.
* Due to the way {@link Spannable}s work, any argument's spans will can only be included <b>once</b> in the result.
* Any duplicates will appear as text only.
*
* @param format the format string (see {@link java.util.Formatter#format})
* @param args
* the list of arguments passed to the formatter. If there are
* more arguments than required by {@code format},
* additional arguments are ignored.
* @return the formatted string (with spans).
*/
public static SpannedString format(CharSequence format, Object... args) {
return format(Locale.getDefault(), format, args);
}
/**
* Version of {@link String#format(Locale, String, Object...)} that works on {@link Spanned} strings to preserve rich text formatting.
* Both the {@code format} as well as any {@code %s args} can be Spanned and will have their formatting preserved.
* Due to the way {@link Spannable}s work, any argument's spans will can only be included <b>once</b> in the result.
* Any duplicates will appear as text only.
*
* @param locale
* the locale to apply; {@code null} value means no localization.
* @param format the format string (see {@link java.util.Formatter#format})
* @param args
* the list of arguments passed to the formatter.
* @return the formatted string (with spans).
* @see String#format(Locale, String, Object...)
*/
public static SpannedString format(Locale locale, CharSequence format, Object... args){
SpannableStringBuilder out = new SpannableStringBuilder(format);
int i = 0;
int argAt = -1;
while (i < out.length()){
Matcher m = FORMAT_SEQUENCE.matcher(out);
if (!m.find(i)) break;
i=m.start();
int exprEnd = m.end();
String argTerm = m.group(1);
String modTerm = m.group(2);
String typeTerm = m.group(3);
CharSequence cookedArg;
if (typeTerm.equals("%")){
cookedArg = "%";
}else if (typeTerm.equals("%")){
cookedArg = "\n";
}else{
int argIdx = 0;
if (argTerm.equals("")) argIdx = ++argAt;
else if (argTerm.equals("<")) argIdx = argAt;
else argIdx = Integer.parseInt(argTerm.substring(0, argTerm.length() - 1)) -1;
Object argItem = args[argIdx];
if (typeTerm.equals("s") && argItem instanceof Spanned){
cookedArg = (Spanned) argItem;
}else{
cookedArg = String.format(locale, "%"+modTerm+typeTerm, argItem);
}
}
out.replace(i, exprEnd, cookedArg);
i += cookedArg.length();
}
return new SpannedString(out);
}
}
\ No newline at end of file
package de.kuschku.quasseldroid_ng.util;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.support.annotation.ColorInt;
import de.kuschku.quasseldroid_ng.R;
public class ThemeUtil {
public final Colors colors = new Colors();
private static final int[] ATTRS_SENDER = {
// sender colors
R.attr.senderColor0,
R.attr.senderColor1,
R.attr.senderColor2,
R.attr.senderColor3,
R.attr.senderColor4,
R.attr.senderColor5,
R.attr.senderColor6,
R.attr.senderColor7,
R.attr.senderColor8,
R.attr.senderColor9,
R.attr.senderColorA,
R.attr.senderColorB,
R.attr.senderColorC,
R.attr.senderColorD,
R.attr.senderColorE,
R.attr.senderColorF,
};
private static final int[] ATTRS_MIRC = {
// mirc colors
R.attr.mircColor0,
R.attr.mircColor1,
R.attr.mircColor2,
R.attr.mircColor3,
R.attr.mircColor4,
R.attr.mircColor5,
R.attr.mircColor6,
R.attr.mircColor7,
R.attr.mircColor8,
R.attr.mircColor9,
R.attr.mircColorA,
R.attr.mircColorB,
R.attr.mircColorC,
R.attr.mircColorD,
R.attr.mircColorE,
R.attr.mircColorF,
};
private static final int[] ATTRS_GENERAL = {
// General UI colors
R.attr.colorForeground,
R.attr.colorForegroundHighlight,
R.attr.colorForegroundSecondary,
R.attr.colorBackground,
R.attr.colorBackgroundHighlight,
R.attr.colorBackgroundCard,
};
private static final int[] ATTRS_TINT = {
// Tint colors
R.attr.colorTintActivity,
R.attr.colorTintMessage,
R.attr.colorTintHighlight
};
public ThemeUtil(Context ctx) {
initColors(ctx.getTheme());
}
public void initColors(Resources.Theme theme) {
TypedArray arr;
arr = theme.obtainStyledAttributes(ATTRS_SENDER);
for (int i = 0; i < colors.senderColors.length;i++) {
colors.senderColors[i] = arr.getColor(i, colors.transparent);
}
arr.recycle();
arr = theme.obtainStyledAttributes(ATTRS_MIRC);
for (int i = 0; i < colors.senderColors.length;i++) {
colors.mircColors[i] = arr.getColor(i, colors.transparent);
}
arr.recycle();
arr = theme.obtainStyledAttributes(ATTRS_GENERAL);
colors.colorForeground = arr.getColor(0, colors.transparent);
colors.colorForegroundHighlight = arr.getColor(1, colors.transparent);
colors.colorForegroundSecondary = arr.getColor(2, colors.transparent);
colors.colorBackground = arr.getColor(3, colors.transparent);
colors.colorBackgroundHighlight = arr.getColor(4, colors.transparent);
colors.colorBackgroundCard = arr.getColor(5, colors.transparent);
arr.recycle();
arr = theme.obtainStyledAttributes(ATTRS_TINT);
colors.colorTintActivity = arr.getColor(0, colors.transparent);
colors.colorTintMessage = arr.getColor(1, colors.transparent);
colors.colorTintHighlight = arr.getColor(2, colors.transparent);
arr.recycle();
}
public static class Colors {
@ColorInt public int transparent = 0x00000000;
@ColorInt public int[] senderColors = new int[16];
@ColorInt public int[] mircColors = new int[16];
@ColorInt public int colorForeground = 0x00000000;
@ColorInt public int colorForegroundHighlight = 0x00000000;
@ColorInt public int colorForegroundSecondary = 0x00000000;
@ColorInt public int colorBackground = 0x00000000;
@ColorInt public int colorBackgroundHighlight = 0x00000000;
@ColorInt public int colorBackgroundCard = 0x00000000;
@ColorInt public int colorTintActivity = 0x00000000;
@ColorInt public int colorTintMessage = 0x00000000;
@ColorInt public int colorTintHighlight = 0x00000000;
}
}
......@@ -22,9 +22,17 @@ public class ObservableList<T extends ContentComparable<T>> {
}
public T last() {
if (list.size() == 0) return null;
return list.get(list.size() - 1);
}
public T first() {
if (list.size() == 0) return null;
return list.get(0);
}
public interface UICallback {
void notifyItemInserted(int position);
......
......@@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout"
tools:context="de.kuschku.quasseldroid_ng.MainActivity"
tools:context=".ui.MainActivity"
android:orientation="vertical" >
<android.support.design.widget.AppBarLayout
......
......@@ -5,13 +5,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/activity_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/messages"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeview"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="?attr/messagesBackground" />
android:background="?attr/colorBackground" >
<android.support.v7.widget.RecyclerView
android:id="@+id/messages"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
<View
android:layout_width="fill_parent"
......
......@@ -7,14 +7,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/server"
android:inputType="textUri"
android:text="192.168.178.241"/>
android:inputType="textUri" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/port"
android:inputType="number"
android:text="@string/default_port" />
android:inputType="number" />
</LinearLayout>
\ No newline at end of file
......@@ -6,14 +6,12 @@
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/username"
android:text="test"/>
android:id="@+id/username" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:inputType="textPassword"
android:text="password"/>
android:inputType="textPassword" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
android:minHeight="?android:attr/listPreferredItemHeightSmall" >
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="monospace"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingRight="?android:attr/listPreferredItemPaddingRight" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="iconServer" format="reference" />
<attr name="messagesBackground" format="reference" />
<attr name="chatlineBackground" format="reference" />
<attr name="dividerColor" format="reference"/>
<!-- sender colors -->
<attr name="senderColor0" format="color" />
<attr name="senderColor1" format="color" />
<attr name="senderColor2" format="color" />
<attr name="senderColor3" format="color" />
<attr name="senderColor4" format="color" />
<attr name="senderColor5" format="color" />
<attr name="senderColor6" format="color" />
<attr name="senderColor7" format="color" />
<attr name="senderColor8" format="color" />
<attr name="senderColor9" format="color" />
<attr name="senderColorA" format="color" />
<attr name="senderColorB" format="color" />
<attr name="senderColorC" format="color" />
<attr name="senderColorD" format="color" />
<attr name="senderColorE" format="color" />
<attr name="senderColorF" format="color" />
<!-- mirc colors -->
<attr name="mircColor0" format="color" />
<attr name="mircColor1" format="color" />
<attr name="mircColor2" format="color" />
<attr name="mircColor3" format="color" />
<attr name="mircColor4" format="color" />
<attr name="mircColor5" format="color" />
<attr name="mircColor6" format="color" />
<attr name="mircColor7" format="color" />
<attr name="mircColor8" format="color" />
<attr name="mircColor9" format="color" />
<attr name="mircColorA" format="color" />
<attr name="mircColorB" format="color" />
<attr name="mircColorC" format="color" />
<attr name="mircColorD" format="color" />
<attr name="mircColorE" format="color" />
<attr name="mircColorF" format="color" />
<!-- Background and foreground colors for UI -->
<attr name="colorForeground" format="color" />
<attr name="colorForegroundHighlight" format="color" />
<attr name="colorForegroundSecondary" format="color" />
<attr name="colorBackground" format="color" />
<attr name="colorBackgroundHighlight" format="color" />
<attr name="colorBackgroundCard" format="color" />
<!-- Tint colors for drawer -->
<attr name="colorTintActivity" format="color" />
<attr name="colorTintMessage" format="color" />
<attr name="colorTintHighlight" format="color" />
</resources>
\ No newline at end of file
......@@ -2,4 +2,31 @@
<string name="app_name">QuasselDroid</string>
<string name="action_settings">Settings</string>
<string name="default_port">4242</string>
<string name="username_hostmask">%1$s (%2$s)</string>
<!-- Message format strings -->
<string name="message_plain">%1$s: %2$s</string>
<string name="message_join">%1$s has joined %2$s</string>
<string name="message_part">%1$s has left %2$s</string>
<string name="message_part_extra">"%1$s has left %2$s (%3$s)</string>
<string name="message_quit">%1$s has quit</string>
<string name="message_quit_extra">%1$s has quit (%2$s)</string>
<string name="message_kill">%1$s was killed: %2$s</string>
<string name="message_kick">%1$s has kicked %2$s from %3$s</string>
<string name="message_kick_extra">%1$s has kicked %2$s from %3$s: %4$s</string>
<string name="message_mode">Mode %1$s by %2$s</string>
<string name="message_nick_self">You are now known as %1$s</string>
<string name="message_nick_other">%1$s is now known as %2$s</string>
<string name="message_daychange">{ Day changed to %1$s }</string>
<string name="message_action">* %1$s %2$s</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<style name="AppTheme" parent="MaterialDrawerTheme">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="iconServer">@drawable/ic_server_light</item>
<item name="dividerColor">@color/material_drawer_dark_divider</item>
<item name="messagesBackground">@color/messagesBackgroundDark</item>
<item name="chatlineBackground">@color/md_dark_cards</item>
</style>
<style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme.Light" parent="MaterialDrawerTheme.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="iconServer">@drawable/ic_server_dark</item>
<item name="dividerColor">@color/material_drawer_divider</item>
<item name="messagesBackground">@color/messagesBackgroundLight</item>
<item name="chatlineBackground">@color/md_light_cards</item>
......@@ -28,5 +26,4 @@
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Material_Dark" parent="AppTheme">
<item name="senderColor0">@color/md_pink_500</item>
<item name="senderColor1">@color/md_purple_500</item>
<item name="senderColor2">@color/md_red_500</item>
<item name="senderColor3">@color/md_green_500</item>
<item name="senderColor4">@color/md_cyan_500</item>
<item name="senderColor5">@color/md_deep_purple_500</item>
<item name="senderColor6">@color/md_amber_500</item>
<item name="senderColor7">@color/md_blue_500</item>
<item name="senderColor8">@color/md_pink_500</item>
<item name="senderColor9">@color/md_purple_500</item>
<item name="senderColorA">@color/md_red_500</item>
<item name="senderColorB">@color/md_green_500</item>
<item name="senderColorC">@color/md_cyan_500</item>
<item name="senderColorD">@color/md_deep_purple_500</item>
<item name="senderColorE">@color/md_amber_500</item>
<item name="senderColorF">@color/md_blue_500</item>
<item name="colorForeground">@color/md_dark_primary_text</item>
<item name="colorForegroundHighlight">@color/md_dark_primary_text</item>
<item name="colorForegroundSecondary">@color/md_dark_secondary</item>
<item name="colorBackground">@color/md_dark_background</item>
<item name="colorBackgroundHighlight">#ff8811</item>
<item name="colorBackgroundCard">@color/md_dark_cards</item>
<item name="colorTintActivity">#88cc33</item>
<item name="colorTintMessage">#2277dd</item>
<item name="colorTintHighlight">#ff8811</item>
</style>
<style name="Material_Light" parent="AppTheme">
<item name="senderColor0">@color/md_pink_500</item>
<item name="senderColor1">@color/md_purple_500</item>
<item name="senderColor2">@color/md_red_500</item>
<item name="senderColor3">@color/md_green_500</item>
<item name="senderColor4">@color/md_cyan_500</item>
<item name="senderColor5">@color/md_deep_purple_500</item>
<item name="senderColor6">@color/md_amber_500</item>
<item name="senderColor7">@color/md_blue_500</item>
<item name="senderColor8">@color/md_pink_500</item>
<item name="senderColor9">@color/md_purple_500</item>
<item name="senderColorA">@color/md_red_500</item>
<item name="senderColorB">@color/md_green_500</item>
<item name="senderColorC">@color/md_cyan_500</item>
<item name="senderColorD">@color/md_deep_purple_500</item>
<item name="senderColorE">@color/md_amber_500</item>
<item name="senderColorF">@color/md_blue_500</item>
<item name="colorForeground">@color/md_light_primary_text</item>
<item name="colorForegroundHighlight">@color/md_light_primary_text</item>
<item name="colorForegroundSecondary">@color/md_light_secondary</item>
<item name="colorBackground">@color/md_light_background</item>
<item name="colorBackgroundHighlight">#ff8811</item>
<item name="colorBackgroundCard">@color/md_light_cards</item>
<item name="colorTintActivity">#88cc33</item>
<item name="colorTintMessage">#2277dd</item>
<item name="colorTintHighlight">#ff8811</item>
</style>
<style name="Quassel" parent="AppTheme.Light">
<item name="senderColor0">#e90d7f</item>
<item name="senderColor1">#8e55e9</item>
<item name="senderColor2">#b30e0e</item>
<item name="senderColor3">#17b339</item>
<item name="senderColor4">#58afb3</item>
<item name="senderColor5">#9d54b3</item>
<item name="senderColor6">#b39775</item>
<item name="senderColor7">#3176b3</item>
<item name="senderColor8">#e90d7f</item>
<item name="senderColor9">#8e55e9</item>
<item name="senderColorA">#b30e0e</item>
<item name="senderColorB">#17b339</item>
<item name="senderColorC">#58afb3</item>
<item name="senderColorD">#9d54b3</item>
<item name="senderColorE">#b39775</item>
<item name="senderColorF">#3176b3</item>
<item name="colorForeground">@color/md_light_primary_text</item>
<item name="colorForegroundHighlight">@color/md_light_primary_text</item>
<item name="colorForegroundSecondary">@color/md_light_secondary</item>
<item name="colorBackground">@color/md_light_background</item>
<item name="colorBackgroundHighlight">#ff8811</item>
<item name="colorBackgroundCard">@color/md_light_cards</item>
<item name="colorTintActivity">#88cc33</item>
<item name="colorTintMessage">#2277dd</item>
<item name="colorTintHighlight">#ff8811</item>
</style>
</resources>
\ No newline at end of file
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment