Unjank character count indicators

Fixes #1841
// FREEBIE
This commit is contained in:
Jake McGinty
2015-02-16 02:38:09 -08:00
parent fc21d2038f
commit f818cfa32b
8 changed files with 132 additions and 67 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright (C) 2011 Whisper Systems
* Copyright (C) 2015 Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,29 +16,9 @@
*/
package org.thoughtcrime.securesms.util;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
public class CharacterCalculator {
public CharacterState calculateCharacters(int charactersSpent) {
int maxMessageSize;
if (charactersSpent <= SmsTransportDetails.SMS_SIZE) {
maxMessageSize = SmsTransportDetails.SMS_SIZE;
} else {
maxMessageSize = SmsTransportDetails.MULTIPART_SMS_SIZE;
}
int messagesSpent = charactersSpent / maxMessageSize;
if (((charactersSpent % maxMessageSize) > 0) || (messagesSpent == 0))
messagesSpent++;
int charactersRemaining = (maxMessageSize * messagesSpent) - charactersSpent;
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
public abstract class CharacterCalculator {
public abstract CharacterState calculateCharacters(int charactersSpent);
public class CharacterState {
public int charactersRemaining;

View File

@@ -18,7 +18,7 @@ package org.thoughtcrime.securesms.util;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
public class EncryptedCharacterCalculator extends CharacterCalculator {
public class EncryptedSmsCharacterCalculator extends CharacterCalculator {
private CharacterState calculateSingleRecordCharacters(int charactersSpent) {
int charactersRemaining = SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE - charactersSpent;
@@ -41,7 +41,7 @@ public class EncryptedCharacterCalculator extends CharacterCalculator {
@Override
public CharacterState calculateCharacters(int charactersSpent) {
if (charactersSpent <= SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE){
if (charactersSpent <= SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE) {
return calculateSingleRecordCharacters(charactersSpent);
} else {
return calculateMultiRecordCharacters(charactersSpent);

View File

@@ -0,0 +1,26 @@
/**
* Copyright (C) 2015 Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.util;
public class PushCharacterCalculator extends CharacterCalculator {
private static final int MAX_SIZE = 2000;
@Override
public CharacterState calculateCharacters(int charactersSpent) {
return new CharacterState(1, MAX_SIZE - charactersSpent, MAX_SIZE);
}
}

View File

@@ -0,0 +1,43 @@
/**
* Copyright (C) 2011 Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.util;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
public class SmsCharacterCalculator extends CharacterCalculator {
@Override
public CharacterState calculateCharacters(int charactersSpent) {
int maxMessageSize;
if (charactersSpent <= SmsTransportDetails.SMS_SIZE) {
maxMessageSize = SmsTransportDetails.SMS_SIZE;
} else {
maxMessageSize = SmsTransportDetails.MULTIPART_SMS_SIZE;
}
int messagesSpent = charactersSpent / maxMessageSize;
if (((charactersSpent % maxMessageSize) > 0) || (messagesSpent == 0))
messagesSpent++;
int charactersRemaining = (maxMessageSize * messagesSpent) - charactersSpent;
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
}